Jump to content

Jquery repeat event on mousedown?


sloth456

Recommended Posts

Hi,

 

I've already had help creating my own spinbox wich looks like this

 

- 0 +

 

When you click the plus button the number increments by 1 and decrements by 1 if you click the minus button.

 

The code for this is below

 

<html>
<body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>

<script type="text/javascript">
$(document).ready(function() {
   
    $('.minus').click(function() {
        var curr = parseInt($(this).parent().find('.cdisp').html());
        if (curr > 0) {
            $(this).parent().find('.cdisp').html(curr-1);
            $('#spare').html(parseInt($('#spare').html())+1);
        }
    });


    $('.plus').click(function() {
        var curr = parseInt($(this).parent().find('.cdisp').html());
        if (parseInt($('#spare').html()) > 0)  {
            $(this).parent().find('.cdisp').html(curr+1);
            $('#spare').html(parseInt($('#spare').html())-1);

        }
    });

});

</script>

Spare Points: <div id="spare">100</div>
<div>
<div>Campaign Name  Priority</div>

<div class="camp">
Campaign 1             <span class="minus">-</span> <span class="cdisp">0</span> <span class="plus">+</span>
</div>
<div class="camp">
Campaign 2             <span class="minus">-</span> <span class="cdisp">0</span> <span class="plus">+</span>
</div>
<div class="camp">
Campaign 3             <span class="minus">-</span> <span class="cdisp">0</span> <span class="plus">+</span>
</div>
</body>
</html>

 

How can I make it so that if I click and hold the mousebutton on either the plus or minus, the number will continue incrementing/decrementing without me having to click the buttons over and over?

 

Thank you for any help in advance :)

Link to comment
https://forums.phpfreaks.com/topic/182636-jquery-repeat-event-on-mousedown/
Share on other sites

Im guessing that to insure the functionality you want is available across all browsers then you need to use the plugin.  click by itself wont work because the click isnt triggered untill mouseup I dont believe.  And I believe webkit browsers dont send mousedown the same as others.  So your best bet is the plugin.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.