Submit your widget

jQuery Awesome Mousehold Event

Created 7 years ago   Views 15521   downloads 2015    Author remysharp
jQuery Awesome Mousehold Event
View DemoDownload 18.0 KB
Share |

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.

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).

js code:

running = true;
     var pipDiv = this;
     $('a', pipDiv).each(function(){
      var href = $(this).href()
      $(this).mousehold(function(i) {
       var pip = parseFloat($('input#pip').val())
       var hrefPip = parseFloat(href.match(/spin=([\-0-9\.]+)/)[1])
       var dp = parseInt($('input#dp').val())
       if (hrefPip < 0) pip *= -1
       if (!pip) pip = hrefPip
       var s = new stepper(pip, dp)
/*       console.log("hit number", i)*/
       var v = parseFloat($('input', pipDiv).val())
       $('input', pipDiv).val(s.step(v))
    $('div.pipTicker a').click(function(){ return false })

Tag: mousehold