The following function moves a scrolling panel up and or down based on which element is clicked. The problem is that if the user double clicks then the variable named offset does not establish the position correctly as the previous animation has not ended. What we need is a way of queueing the animation but I do not know how to do this.
I tried a timeout but it triggers the timeout function during the the current timeout so thats no good either.
var offset = 0;
$('#leftwheel li').click(function() {
var leftid = '#BKD' + $('#sLeft').val();
var doubleforward = $(leftid).next().next().attr('id');
var doublebackward = $(leftid).prev().prev().attr('id');
var offsettots = ($(this).parent().height() - 16) / 32;
var $this = this;
var offset = $($this).parent().position().top;
if('#' + $($this).attr('id') == leftid) { return false; }
else if($($this).attr('id') == doubleforward) {
offset += -64;
myScroll2.scrollTo(0, offset, 400);
}
else if($($this).attr('id') == doublebackward) {
offset += 64;
myScroll2.scrollTo(0, offset, 400);
}
else if('#' + $($this).attr('id') > leftid) {
o开发者_如何学Cffset += -32;
myScroll2.scrollTo(0, offset, 250);
}
else if('#' + $($this).attr('id') < leftid) {
offset += 32;
myScroll2.scrollTo(0, offset, 250);
}
});
Any ideas?
Marvellous
Kind of a guess but:
$('#leftwheel li').dblclick(function(e) {
e.preventDefault()
});
should do the trick assuming that #leftwheel li
is the element you want to disable double clicks on.
Set a flag at the beginning and reset it at the end then only execute the code if the flag is true.
var flag = true;
$('#leftwheel li').click(function() {
if ( flag ) {
flag = false;
// Your code here
flag = true;
}
});
精彩评论