简体   繁体   English

滚动到特定div时隐藏div

[英]Hiding a div once scrolling past a specific div

I have a slideshow that has a height set to auto so any height image can be displayed. 我有一个幻灯片,其高度设置为自动,因此可以显示任何高度的图像。 Within that slideshow I have two arrows which are wrapped in a div with a class of .center. 在该幻灯片中,我有两个箭头,它们被包裹在带有.center类的div中。 The arrows are at a fixed position so when scrolling the arrows would follow. 箭头位于固定位置,因此滚动时会跟随箭头。 The function that is assigned to div="center" will display when you scroll over the div .center. 当您在div .center上滚动时,将显示分配给div =“ center”的函数。

The problem I am having is once I scroll past the slide show div the arrows are still present. 我遇到的问题是,当我滚动浏览幻灯片div后,箭头仍然存在。 But when I scroll up past my slide show div the arrows are hidden. 但是,当我向上滚动通过幻灯片div时,箭头被隐藏了。

How can I set up my script for when I scroll down to div 2 or end of slide show which has a class of cs-slider the center will be hidden? 向下滚动到div 2或幻灯片放映结束时该如何设置脚本,其中放有一类cs-slider,中心将被隐藏?

 $(window).scroll(function() {
    $(".center").each( function() {
      if( $(window).scrollTop() > $(this).offset().top - 150 ) {
        $(this).css('opacity',1);
      } else {
        $(this).css('opacity',0);
      }
    }); 
 });

HTML HTML

 <section class="cs-slider" style="margin-bottom: 80px;" >
  <div class="center" id="box" >
      <a href=# id="prev">Prev</a> 
      <a href=# id="next">Next</a>
  </div>
     <div class="slides cycle-slideshow"
        data-cycle-fx="fade"
        data-cycle-prev="#prev"
        data-cycle-next="#next"
       data-cycle-pager=".pager"
        data-cycle-loader="wait"
        data-cycle-swipe=true
        data-cycle-swipe-fx=scrollHorz
        data-cycle-auto-height=container
        data-cycle-center-horz=true
       data-cycle-timeout="0"
        data-cycle-speed="500"
>
<div class="pager"></div>
  </div>
  </section><!-- slider -->
  <section class="workContent fadeDown"><!-- Hide .center once you scroll over section -->

  </section>

CSS CSS

 cs-slider .slides  { margin:0 auto; max-width:800px; display:block; z-index:1}
 .cs-slider             { position:relative; text-align:center; padding:4em 0em 1em 0em;}
 .center                    {opacity: 0; }
 #prev, #next               { position:fixed; top: 0%; width: 10%; height: 200px; cursor: pointer; text-indent:-9999px;}
 #prev                      { left: 0;  background: url(http://malsup.github.com/images/left.png) 50% 50% no-repeat; }
 #next                      { right: 0; background: url(http://malsup.github.com/images/right.png) 50% 50% no-repeat;}
 #prev:hover, #next:hover   { opacity: .7; filter: alpha(opacity=70) }
 .disabled                  { opacity: .5; filter:alpha(opacity=50); }

尝试使用以下内容。

$(this).css('display', 'none');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM