基于滚动高度的淡入/淡出

时间:2013-11-03 23:20:55

标签: javascript jquery scroll fadein fadeout

.secondLogo超过1000px时,我有以下内容可以scrollToTop出现(通过淡入)

var secondLogo = $(".secondLogo");
$(window).scroll(function(){
  //more then or equals to
  if($(window).scrollTop() >= 1000 ){
       secondLogo.fadeIn();

  //less then 1000px from top
  } else {
     secondLogo.fadeOut();

  }
});

HTML

<div class="secondLogo">
    <img src="images/smm_logo_large.png" alt="Student Makers Market logo"/>
</div>

CSS

.secondLogo{
    opacity:0;
    position:fixed;
    z-index:-10;
    top: 15%;
    left: 3%;
    opacity:0.1;
    filter:alpha(opacity=10); /* For IE8 and earlier */
}

1 个答案:

答案 0 :(得分:2)

$.fn.fadeIn$.fn.fadeOut不会操纵css属性opacity。使用display:none初始化您的元素

.secondLogo {
    display: none;
    position: fixed;
    z-index: -10;
    top: 15%;
    left: 3%;
}