I'm using the scrollTo plugin and executing it in a callback function of an animate method within a 'click' event.
The page scrolls just fine, but then if I use the mousewheel or scrollbar to try and go back up, it won't let me. It's just kind of stuck and fights with me - creating a jumping effect. after a second or so, it resumes to normal behaviour.
I can't show the exact place this is happening (not permitted to) but I have copied my code below:
// This function finds the first item that has an opacity set to 1 (full)
function moveIt() {
var theItem = $('.work').filter( function(j) { return $(this).css('opacity') == 1 } ).eq(0);
$("html").scrollTo( theItem, 350 );
}
$("#work-menu-client a").click(开发者_运维知识库
function () {
var val = $(this).attr("href");
val = val.substring(1, val.length);
if( val.length ) {
$(".work[data-client*='" + val + "']").animate({
opacity: 1
}, 350, function() {
// Complete
});
$(".work:not([data-client*='" + val + "'])").animate({
opacity: 0.05
}, 350, function() {
moveIt();
});
}
return false;
},
function () {
return false;
}
);
Don't worry about what this whole thing does, but there's something not right with placing this code into the callback function. Almost like it keeps looping / repeating the callback so I can't go back up.
(If you want to know, basically, a menu allows me to fade in and out certain items based on their attribute, then I scroll to the first occurance of where the opacity wasn't faded out.)
Any help would be greatly appreciated.
I located someone with a similar problem but it hasn't been solved and there's little feedback on there: JQUERY, scrollTo, after scrolling down, the page won't let me scroll up for a second... Y?
Many thanks, Michael.
EDIT: In fact, I have just noticed that I can't scroll down either...so essentially, I'm stuck in the position it sent me to.
I had this issue too, but the bug/fix was not about the selector logic.
The problem was that I was binding click handlers onto the anchor that was triggering the scrollTo more than once, without unbinding old ones. I was implementing ajax loading and re-registering event handlers but not de-registering old ones. The fix just involved a call to $(selector).off() before $(selector).on(...)
, which I didn't have to change since it was behavior that I still wanted.
精彩评论