sloth456 Posted November 23, 2009 Share Posted November 23, 2009 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 Quote Link to comment Share on other sites More sharing options...
JustLikeIcarus Posted November 23, 2009 Share Posted November 23, 2009 Checkout this plugin for mousehold http://remysharp.com/2006/12/15/jquery-mousehold-event/ you will need to alter your function to fire on mousehold. Quote Link to comment Share on other sites More sharing options...
sloth456 Posted November 23, 2009 Author Share Posted November 23, 2009 I looked at that myself before posting here. I tried to figure out how the code in the plugin worked. It seems an awful lot of code for what I want to do, surely there must be a simpler way? Quote Link to comment Share on other sites More sharing options...
JustLikeIcarus Posted November 24, 2009 Share Posted November 24, 2009 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.