javascript 隐藏元素滚动

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 隐藏元素滚动相关的知识,希望对你有一定的参考价值。

<img alt="Wilderly Bride" src="/assets/1550/collection-wilderly.jpg" class="hidden-element">
.hidden-element {
  opacity: 0;
  position: relative;
}
.hidden-element.element-load {
  animation: fade-in 0.75s linear forwards;
}
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
  /* ==========================================================================
  Hidden before scroll
  ========================================================================== */


  $(window).scroll( function(){

    // trigger script when target is in view
    $('.hidden-element').each(function(){

      var bottom_of_object = $(this).offset().top + $(this).outerHeight();
      var bottom_of_window = $(window).scrollTop() + $(window).height();

      // get half height of object
      bottom_of_object -= $(this).outerHeight() / 2;

      // If the object is halfway visible in the window, fade it in
      if (bottom_of_window > bottom_of_object){
      $(this).addClass('element-load');
      }
    });
  }); 
  

以上是关于javascript 隐藏元素滚动的主要内容,如果未能解决你的问题,请参考以下文章

javascript 隐藏元素滚动

使用纯 Javascript 滚动到可滚动 DIV 内的元素

使用纯 Javascript 滚动到可滚动 DIV 内的元素

javascript [滚动隐藏标题]滚动#javascript时隐藏标题

overflow-y: hidden 隐藏了上下滚动条以后鼠标滚球无法滚动?

CSS隐藏滚动条,但元素可滚动