scroll with mouse wheel and mouse movement - javascript

I try to make a gallery that I can move in its content with mouse wheel or with mouse movement.
I used the following script for mouse movement http://valums.com/files/2009/menu/final.htm and for mouse wheel I use Mouse Wheel Plugin.
Separately they work great but when I try to combine them I have some problems. Check the following demo:
http://jsfiddle.net/A93mF/
As you can see partially works but, and I say partially because when I use mouse wheel to scroll it's ok, but when I move a bit the cursor then returns in the previous position.
How can I make it so, if I scroll and then move the cursor to continue normally the scrolling instead of return in the previous position?
Any solution is acceptable (change javascript[jQuery], html structure, plugin or whatever)

I rewrote the mouse movement script and now I think is works fine and in Chrome also (thanks #Nicola Peluchetti ) For anyone interested can check the following demo: http://jsfiddle.net/A93mF/3/

Related

Bind buttons for + or - mouse wheel

Recently I got an edited version of the JavaScript "Reel" by Pisi, which allows the user to use the mouse wheel to zoom in on a picture. The "reel" itself is working as a 360 view of an object, using many images which will jump to the next image in order when using mouse drag.
However, since I will use this application on a touch screen without a mouse I was thinking about rebinding the mouse wheel or adding events to a button which works like the mouse wheel. For example, below the DIV with the 360-slider I want two buttons, one that zooms in and one that zooms out. Any idea on how to make this work?
Any help is much appreciated!

Zooming image to mouse cursor with Javascript and returning to the images original position

Part of my app requires the user to be able to use the mousewheel to zoom in on an image which is already centered inside a larger container element.
I am using jQueryUI to provide a slider with which the zoom is controlled manually.
When zooming withe mousewheel, the viewport adjusts so that the user is always zooming towards to mouse cursor providing exactly the same behaviour as google maps in terms of zoom functionality.
Also, in order to provide a better experience than using css transitions I have written a momentum based smooth scroll algorithm to make the zooming as smooth as possible.
Everything works perfectly with one exception.
To replicate the problem please follow these steps on the provided jsFiddle:
move mouse cursor to the center of the image.
Very gently move the mousewheel one notch so that the smoothwheel takes over an zooms you in a little.
Then move the mouse cursor to another point of the already slightly zoomed image
Zoom in again, as far as you want this time
Finally zoom all the way out
You will see that the zoomed out image is now misplaced (as the translates have not been removed).
The behaviour I want is for the zoomed out image to return to its original position once the scale is set back to 1.
If you remove the css translate from the image in Firebug you will see that the image returns to the correct location.
Therefore this could easily be achieved with a simple conditional like so:
if(scale == 1){
//remove transforms completely
}
However doing this would provide a jumpy experience and I would like the image to gradually zoom back out to the original position as the user zooms out.
It is worth mentioning that if you zoom all the way in without moving the mouse you will find that everything is correct when you zoom back out. This is simple because no translate gets added to the elements transform, simply a scale and transform-origin. In my code the translate only gets added when you change zoom position with the mouse mid zoom.
Unfortunately I cant seem to get my head around the best way of going about this.
Here is a working jsFiddle:
http://jsfiddle.net/3k332/15/
Thanks in advance for any help.
NOTE: I am well aware that there is some redundant code in my fiddle and that its not particularly elegant but this is merely a quick mock up to help you understand the problem.

Zoom in on mouse position in KineticJS

Question:
How do I zoom in on the mouse position on mouse wheel scrolls?
Details:
I am trying to merge this complete solution on Stack Overflow, which allows for zooming of the stage, with this incomplete solution, which allows for zooming in around the mouse when clicked. I have forked the jsfiddle code here. The code works fine once you get it zoomed in, but upon first scrolling, the stage jumps to a different location and I can't figure out why. Can anyone tell me why it is happening, and how to solve it. Thanks.
Just a guess, but you are using the mouse position relative to the page not the canvas
When you zoom, the position under your mouse position gets changed (the reason of jumping). To move back the position to its original position, you need to pan the offset( difference between the previous position and the new position(after zoom)). To avoid stage jumping to a different location, you can use stage.setOffset function of KineticJS.
JSFiddle: http://jsfiddle.net/rpaul/ckwu7u86/3/

Mouse wheel event over Raphael element

I need to perform an action if someone uses the wheel when the mouse is positioned over a Raphael element.
I tried several methods but none of it worked. Can you point me in the right direction with an example?
See live demo at http://jsfiddle.net/qiao/6JJrz/6/ (try mouse wheel up and down on the circle)
I used jQuery.mousewheel plugin taken from https://github.com/brandonaaron/jquery-mousewheel
EDITED: sorry, the original link was outdated, I fixed it now.

Determine scroll move

Good day. I got an HTML page which is small and has no scroll bar. However i need to determine when and what direction scroller was moved. So i need to determine scroll button on my mouse is moving.
How can i do it?
Check out the jQuery Mousewheel plugin. Then you can simply bind an event to any element to check if the wheel was used while the mouse was over it.
$('body').mousewheel(function(delta){
// Do stuff
});
Note that it's not too user friendly to not have a scrollbar and rely only on the mousewheel. There are other ways people expect to be able to scroll, like the arrow keys for example.

Categories