小编Rik*_*Rik的帖子

仅当滚动位置在2点之间时,才使用jQuery显示div

我试图找出当用户滚动到其包含div的高度(#wrap)的第二个四分之一时如何获得div(#tips),然后当用户滚动到最后一个季度时它消失.所以它会是这样的:

第一季度 - #tips隐藏在
第二季度 - #tips可见
第三季度 - #tips可见
第四季度 - #tips被隐藏

我几乎是jQuery的新手,但到目前为止我得到的是:

function addKeyboardNavigation(){
 // get the height of #wrap
 var $wrapHeight = $('#wrap').outerHeight()
 // get 1/4 of wrapHeight
 var $quarterwrapHeight = ($wrapHeight)/4
 // get 3/4 of wrapHeight
 var $threequarterswrapHeight = 3*($wrapHeight)
 // check if we're over a quarter down the page
 if( $(window).scrollTop() > $quarterwrapHeight ){
  // if we are show keyboardTips
  $("#tips").fadeIn("slow");
 }
}
Run Code Online (Sandbox Code Playgroud)

这是我感到困惑的地方.如何检查滚动位置是否> $ quarterwrapHeight但是<$ threewowwrapHeight?

为了让它运行,我一直在使用:

// Run addKeyboardNavigation on scroll
$(window).scroll(function(){
 addKeyboardNavigation(); …
Run Code Online (Sandbox Code Playgroud)

jquery scroll

11
推荐指数
1
解决办法
5万
查看次数

标签 统计

jquery ×1

scroll ×1