English 中文(简体)
基于滚动的 jj 淡入和淡出查询
原标题:jQuery to fadeIn and fadeOut based upon scroll

我用下面来改变一个元素的不透明性, 从 0 到 1, 以它们滚动的像素数量为基础, 并且它完美运作 。

$(window).scroll(function() {
  if ($(this).scrollTop() > 200) {
      $("#hook").stop().animate({
          opacity: 1
      }, 300);
  } else {
      $("#hook").stop().animate({
          opacity: 0
      }, 300);
  }
});

我想补充一点,“当用户滚动了500个像素或更多时, 就会把它从后面掉出来。”

最佳回答

我漏掉了什么吗? 这个代码是99%! http://jsfiddle.net/AwnWe/2

$(window).scroll(function() {
  var scrollTop = $(this).scrollTop();
  console.log( Scroll  , scrollTop);
  if (scrollTop > 500 || scrollTop < 200) {
      $("#hook").stop().animate({
          opacity: 0
      }, 300);
  } else {
      $("#hook").stop().animate({
          opacity: 1
      }, 300);
  }
});​
问题回答

我想您可能会更改 $( this) 。 scrollTop () & gt; 200 改为 $( this).scrollTop () & gt; 200 & amp; & amp; $(this).scrollTop () & lt; 500





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

热门标签