admin管理员组文章数量:1323715
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 mercial 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.
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 mercial 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.
Share Improve this question asked Aug 31, 2011 at 13:11 MHDMHD 1,3602 gold badges13 silver badges18 bronze badges 1- Can you show what you've done so far in a JS Fiddle, or similar, demo? – David Thomas Commented Aug 31, 2011 at 13:24
1 Answer
Reset to default 4You could try to use an existing jQuery plugin, such as MapBox or GZoom:
- http://wayfarerweb./jquery/plugins/mapbox
- http://lab.gianiaz./jquery/gzoom
Or you could try to roll your own. If you do this, there are a three pieces you'll need to put together:
- Use javascript to scale the images in and out http://agilepartners./blog/2005/12/07/iphoto-image-resizing-using-javascript/
- Use javascript to allow you to pan the zoomed-in image
- Capture the scroll wheel movements in javascript http://www.switchonthecode./tutorials/javascript-tutorial-the-scroll-wheel
本文标签: javascriptZooming an image aimed at the mouse cursorStack Overflow
版权声明:本文标题:javascript - Zooming an image aimed at the mouse cursor - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742125997a2421943.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论