English 中文(简体)
利用javascript 套 Interval & clear Interval
原标题:Simulate top scroll using javascript setInterval & clearInterval

我想通过将体/html框架按任意数量向顶级/顶级进行模拟。 我知道j Query scroll或亲密功能,.scroll(.animate()。 但是,我决定不使用这一条,因为它在<条码> scrollTop上造成财产在<条码>、条码/代码>和<条码>上发生冲突。 j an 发生和仍在进行之中的Qu土功能,< scroll被称作。

现在,我的计划是,通过将体/html框架尽可能平稳地以某种任意数量进行模拟,然后在出现本地的<代码>croll(scroll(<>.scroll(>)时,STOP(缩短间隔)。

在<代码>.scroll()时,我可以停止<代码>Interval animation,但我仍然无法将html的标语排在首位,而我想要的是“scroll”(这意味着我只读了部分作品)。

这就是我迄今为止所做的事情:

var scrollTop = //Some arbitrary value
var fakeScroll = setInterval(function(){
      console.log(scrollTop);
      var animObj = $( html,body );
      animObj.top = animObj.offset().top + scrollTop;   
    },500);
    $(document).scroll(function(){
        clearInterval(fakeScroll);
    });

赞赏任何建议/答复。 感谢!

最佳回答

解决这个问题时不使用时间。 由此可见,土著饲养活动和 j鱼是两个不同的发生活动。 我确实非常认真地聆听了来自本土发展(DOMMousewheel 和 mousewheel)的一场特别的滚动活动,当时,我停止了 an。 感谢答复。

问题回答

仅限使用<代码>window.scrollTo(0,Y),同时改用Y值。

这样做,但我认为,这并不影响你重新思考,因为它没有滚动页,而是把内容推向前进。

var scrollTop = 1;
var fakeScroll = setInterval(function() {
    console.log(scrollTop);
    var animObj = $( html,body );
    animObj.offset({ top: animObj.offset().top - scrollTop })
}, 500);
$(document).scroll(function() {
    clearInterval(fakeScroll);
});




相关问题
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.

热门标签