jQuery Mousehold Event
I'm working on a web application for Work and we're working towards recreating an existing desktop application on a web page (don't get me started on that one!).
Anyway, traditional applications have 'spinners' that make numbers or items go up and down (I'm working on that too). This jQuery plugin adds the missing 'repeat' event.
Download the mousehold plugin.
The 'repeat' is when you keep a key pressed down and it keeps printing the character, or you keep the mouse button pressed down and it keeps firing the click event.
The plugin works by setting a 'mousedown' event and keeps firing the function at the given interval until the 'mouseup' event or the mouse moves off the element.
This last logic is because if it wasn't in place, the function specified would keep firing (since the mouse up event fired, but not on the element we set it on).
Here's an example that shows a practical example.
Feedback and so on is welcome. If you're interested in the 'stepper' code, feel free to ask.
Very cool Remy!
Hey, glad to see the error was fixed... great plugin, thanks!
Hi there, if you're after a spinner then it's worth checking this one out. (Uses background image on a textbox to look and act like a spin box.)
Awesome!!! Thanks
i can tunder stand the function of it
Not bad. But I think a typical spinner will also have a longer delay up front to make sure the user is intending to hold down the button, then a much shorter delay when continuing to poll and increment the value.
I like the idea, but it doesn't seem to work with the "this" I need to pass a funciton that would get executed in context of the jquery object, so I could use "this" to reference which element to work with. This is Whay I used.
@ davinci27 - I didn't initially understand what you meant, but I think now you're saying that the function passed in isn't executed against the context of the element the plugin was attached to.
If so, I've found the error and made the change. It was quite simple and doesn't require setting a variable within the jQuery object (which I would generally avoid for fear of conflicts or race conditions):
'this' within the context of the setInterval is Window, rather than the element it was set against. So I've changed the plugin as follows:
This way, as I'm caching this in the t variable, when I execute f.call it's against the correct element.
This has been updated in the plugin code now.
Great timing, I need one now. Thanks
To George, the url you gave, http://www.softwareunity.com/sandbox/JQuerySpinBtn/ is also great.
Thanks to both of you
Nice one!
Just what I needed!
[...] Extra selectors for JQuery Add more selectors to jQuery. Mousewheel Mousewheel event handler. Mousehold Event Add repeating event as the user holds down the mouse. Multiple File Upload Select multiple files [...]