javascript 如何仅在容器的溢出处于活动状态时显示图标

g9icjywg  于 11个月前  发布在  Java
关注(0)|答案(1)|浏览(128)

我想在溢出的div下面添加一个滚动箭头,只有当溢出激活时才能添加。有不同高度的不同容器,我只想让这个滚动箭头出现在溢出的容器上,有没有办法动态地做到这一点?
我已经创建了一个JS小提琴来显示我的html,所以基本上当'幻灯片'内容超过900 px最大高度它得到溢出,但我希望它然后显示箭头或相反的效果,并隐藏箭头,如果溢出不活跃!
https://jsfiddle.net/h7r16cah/

<div class="large-12 columns">

  <div id="" class="large-9 columns page-content-right">
      <div class="slider">
            <div class="slide-large-content">
            </div>
            <div class="slide-small-content">
            </div>
      </div>
  </div> <!---end page content right -->

   <div class="large-9 columns">    
           <div class="scrollarrows-container">
                            <div class="chevron"></div>
                            <div class="chevron"></div>
                            <div class="chevron"></div>
                  </div>
            </div>
   </div>      
</div><!---end large 12 cols -->

字符串
任何帮助将不胜感激,如果你需要更多的信息让我知道!
Thanks in advance

mnemlml8

mnemlml81#

检查溢出,如果溢出处于活动状态,则添加类

$(document).ready(function() {
  // Check for overflow and add class if overflow is active
  $(".scrollarrows-container").each(function() {
    if (this.scrollHeight > this.clientHeight || this.scrollWidth > this.clientWidth) {
      $(this).addClass("active");
    }
  });
});
.scrollarrows-container.active .chevron {
  display: block; /* Display chevron icons when the container has overflow */
}

.page-content-right {
    height: 100%;
    max-height: 900px;
    overflow-y: auto;
    border: none;
    margin: 0 !important;
    padding: 0;
    background: #f5f5f5;
}

.scrollarrows-container {
  position: relative;
  width: 24px;
  height: 24px;
  margin: 0 auto;
}

.chevron {
  position: absolute;
  width: 28px;
  height: 8px;
  opacity: 0;
  transform: scale3d(0.5, 0.5, 0.5);
  animation: move 3s ease-out infinite;
}

.chevron:first-child {
  animation: move 3s ease-out 1s infinite;
}

.chevron:nth-child(2) {
  animation: move 3s ease-out 2s infinite;
}

.chevron:before,
.chevron:after {
  content: ' ';
  position: absolute;
  top: 0;
  height: 100%;
  width: 51%;
  background: #f5af23;
}

.chevron:before {
  left: 0;
  transform: skew(0deg, 30deg);
}

.chevron:after {
  right: 0;
  width: 50%;
  transform: skew(0deg, -30deg);
}

@keyframes move {
  25% {
    opacity: 1;

  }
  33% {
    opacity: 1;
    transform: translateY(30px);
  }
  67% {
    opacity: 1;
    transform: translateY(40px);
  }
  100% {
    opacity: 0;
    transform: translateY(55px) scale3d(0.5, 0.5, 0.5);
  }
  
}

@keyframes pulse {
  to {
    opacity: 1;
  }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="large-12 columns">
  <div id="" class="large-9 columns page-content-right">
    <div class="slider">
      <div class="slide-large-content">
        <!-- Content goes here -->
      </div>
      <div class="slide-small-content">
        <!-- Content goes here -->
      </div>
    </div>
  </div>

  <div class="large-9 columns">
    <div class="scrollarrows-container">
      <div class="chevron"></div>
      <div class="chevron"></div>
      <div class="chevron"></div>
    </div>
  </div>
</div>

相关问题