nishanths / zoom.js Goto Github PK
View Code? Open in Web Editor NEWFork of fat/zoom.js with improvements
Home Page: https://nishanths.github.io/zoom.js
License: MIT License
Fork of fat/zoom.js with improvements
Home Page: https://nishanths.github.io/zoom.js
License: MIT License
I can't seem to find the package on npm under zoom.js.
this is the link I used and the package is not published:
https://www.npmjs.com/package/zoom.js
Do you think you can publish it?
import { zoom } from '@nishanths/zoom.js'
but i got zoom is undefined
to get the opacity transition to work at the end, it should read smtg like:
.zoom-overlay {
opacity: 0;
-webkit-transition: opacity 300ms ease-in-out;
-o-transition: opacity 300ms ease-in-out;
transition: opacity 300ms ease-in-out;
}
.zoom-overlay-open .zoom-overlay {
opacity: 1;
}
.zoom-overlay-transitioning .zoom-overlay {
opacity: 0;
}
.zoom-overlay-open
is remove at transitionEnd
.
I like the simplicity of this library and was considering using it. But it is not the same technique that medium uses to zoom images. They use the lightbox technique which requires 2 versions of the same image; a scaled-down version which is loaded by default and zoomed to the full-size version that is loaded upon click. Like this:
<a href="full.jpg">
<img src="thumb.jpg" />
</a>
In fact, a webpage using zoom.js will be penalized by google's search ranking algorithm for inefficiently formatting images.
https://developers.google.com/speed/pagespeed/insights/?url=https://nishanths.github.io/zoom.js/
Do you have plans to further develop this? I think it would be great it if had the ability to zoom from a scaled-down image to a full-size image. The API could stay the same:
zoom.setup(elem);
Where elem is either a normal img element, or it could be an anchor element wrapping an img element, as above. If an img element, it functions exactly as it does now. If an anchor element, it functions as a lightbox.
import { Config, zoom } from "@nishanths/zoom.js"
const cfg: Config = {
padding: 80,
paddingNarrow: 80,
dismissScrollDelta: 40,
dismissTouchDelta: 40,
}
for (const img of document.querySelectorAll<HTMLImageElement>(`img[data-action="zoom"]`)) {
img.classList.add("zoom-cursor")
img.addEventListener("click", (e) => {
if (e.metaKey || e.ctrlKey) {
window.open(img.src, "_blank")
return
}
img.dataset.action = "zoom-out"
zoom(img, cfg)
img.dataset.action = "zoom"
})
}
If you could please add a data-description or like field to describe and show the users what the image is about. Thanks
I set up a minimum page, and it seems to work fine in all major browsers...except edge. When clicking an image, it zooms in correctly, but when zooming out all other content is gone from the webpage.
@nishanths Have you been thinking about using another image to zoom?
When the original image is very small it make no sense to zoom it.
If this is ported from @fat, shouldn't you include his copyright line in your MIT license?
It would be easier to work with webpack and single page app, and init it manually:
import zoom from 'zoom.js'
zoom.setup(document.querySelectorAll('.my-els'))
use the correct image source for the current viewport size, not src
always.
related: fat/zoom.js#44
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.