Reputation: 6316
I have a button which is like below and a jQuery which increase the size of the slider perfectly:
<button id='plus' type="button">+</button>
$('#plus').click(function() {
s.slider('value', s.slider('value') + s.slider( "option", "step" ) );
});
But I would like to change the size up as long as the mouse is down over the button. I tried this but it didn't do the job! (it is actually acting like click event).
$('#plus').mousedown(function() {
s.slider('value', s.slider('value') + s.slider( "option", "step" ) );
});
How can I do this in jQuery?
Upvotes: 0
Views: 161
Reputation: 5451
i just understood that you want something to continuously happen while the button is pressed down.
see this answer,
the main idea is to start an interval when button is down, which will do the update on every round, and when the button is released, this interval will stop.
for example:
var timeout, clicker = $('#plus');
clicker.mousedown(function(){
timeout = setInterval(function(){
// Do something continuously
s.slider('value', s.slider('value') + s.slider( "option", "step" );
}, 500);
return false;
});
$(document).mouseup(function(){
clearInterval(timeout);
return false;
});
hope that helps.
Upvotes: 1
Reputation: 11278
as bind
is deprecated using on
should be the better solution:
$('#plus').on('mousedown', function() {
s.slider('value', s.slider('value') + s.slider( "option", "step" ) );
});
Upvotes: 0
Reputation: 15767
Try
$('#plus').bind('mousedown', function() { s.slider('value', s.slider('value') + s.slider( "option", "step" ) );
});
OR
$('#plus').on('mousedown', function() { s.slider('value', s.slider('value') + s.slider( "option", "step" ) );
});
Upvotes: 1