English 中文(简体)
允许用户停电,停止对滚动的裂缝 an?
原标题:let user scrolling stop jquery animation of scrolltop?

我想使网站自动浏览某一部分,然而,我并不希望滚动与用户投入——如果它开始滚动,然后是用户的滚动,那么我就希望自动滚动停止,让用户完全控制。

So I originally thought I could do something like this:

var animatable = $( body, html );
animatable.animate({scrollTop: $( #foo ).offset()}, 1000);

$(window).scroll(function() { animatable.stop(); });

然而,问题在于,滚动模型的推测会触发了玻璃窗的滚动活动手! 因此,估算开始,然后立即停止。

我正在寻求一种方式,即我只能把窗户滚动活动手套停下来,如果它是由用户投入引发的。 这是可能的吗?

最佳回答

Diode s solution didn t work for me - scroll() didn t differentiate between the animation and the user, meaning the animation stopped immediately. From a different post, the following works for me (modified for this purpose):

// Assign the HTML, Body as a variable...
var $viewport = $( html, body );

// Some event to trigger the scroll animation (with a nice ease - requires easing plugin )...
$( #element ).click(function() {
    $viewport.animate({ 
        scrollTop: scrollTarget // set scrollTarget to your desired position
    }, 1700, "easeOutQuint");
});

// Stop the animation if the user scrolls. Defaults on .stop() should be fine
$viewport.bind("scroll mousedown DOMMouseScroll mousewheel keyup", function(e){
    if ( e.which > 0 || e.type === "mousedown" || e.type === "mousewheel"){
         $viewport.stop().unbind( scroll mousedown DOMMouseScroll mousewheel keyup ); // This identifies the scroll as a user action, stops the animation, then unbinds the event straight after (optional)
    }
});                 
问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签