Use case:
User clicks a link, a modal window is displayed containing one big image, scaled down to fit this window. When the user scrolls their mousewheel up or down, the image zooms in or out. The image is zoomed at whatever location the mouse cursor is pointing.
Problem:
I can't wrap my brain around the how-to part of doing this.
Current workings:
When a link is clicked, a jQuery plugin creates a "viewer" collection of html elements that are styled with CSS. It's an absolute positioned DIV that contains an IMG-element. The image is scaled to 100% width. When scrolling, the image is increased by 5% per scroll action.
Because the image is scaled up whilst zooming in, the containing DIV (overflow: hidden) will eventually clip the image. The image is draggable so that you can always see all parts of it.
Variables I keep and know:
The image's scaled down ratio. The image's dimensions pre our most recent zoom action. The image's new dimensions after our most recent zoom action. The difference in these two dimensions. The X and Y position of the image. The X and Y position of the mouse cursor, relative to the positioned container DIV.
What I probably need:
I know the variables I need, I just can't grasp in what order to put them and what operators to use when. Math never was my strong suit, neither was grammar. So any help is appreciated.
Research done:
I Googled a lot for existing solutions. Most were implementations of OpenGL or Flash/ActionScript, none of which make any sense to me whatsoever. The few javascript-based examples I found were for commercial purposes, and even then their source code was obfuscated or minified, and I couldn't quite extract the inner workings for this little feature properly.
Also, I probably don't have the correct search words to figure it out, either.
You could try to use an existing jQuery plugin, such as MapBox or GZoom:
Or you could try to roll your own. If you do this, there are a three pieces you'll need to put together:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With