I have a button that moves an element (changing its top
position by 100px
) and that transition takes time (1.5s).
I found that if the user clicks several times and very fast, in the button the the final position won't be the expected as it would start a new transition when still in the middle of the previous one.
My goal would be to make sure every button click will make the element move by 100px
regardless of how fast a user clicks a button, so that next movement would only start after the previous one and so on.
My code is:
var extHeight = parseInt($(this).siblings('.screen').css('height'), 10);
var intHeight = parseInt($(this).children('.wrap').css('height'), 10);
var maxScroll = intHeight - extHeight;
var pos = parseInt($(this).children('.wrap').css('top'), 10);
if (maxScroll - 100 > -pos) {
$(this).children('.wrap').css({'top': pos-100+'px'});
}
I've tried using setTimeout
and also a counter without success.
PS: I'm using this inline.