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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.