Help with implementing a click and hold function
Hello all,
I have a grid of items that when clicked lead to a new page. I would like to implement a function so that if a user clicks on an item and holds for at least 1000ms, a menu will be shown next to the item and they will not be taken to the next page.
However, all of my current attempts either lead to the menu not being shown, or it is shown and the user is redirected to the next page anyways.
Here's my current code:
- jQuery(document).ready(function(){
- var mousehold;
- jQuery('.item').mousedown(function(){
- var selected = jQuery(this);
- var show_menu = function() {
- // show menu for selected
- }
- mousehold = setTimeout(show_menu,1000);
- }).mouseup(function() {
- clearTimeout(mousehold);
- });
- });
Any suggestions?
Cory