scrollTop jQuery,滚动到div不滚动?

时间:2019-01-04 11:08:16

标签: jquery html wordpress scroll scrolltop

我在键盘上遇到了以下代码:https://codepad.co/snippet/YPDXE33r

但是在我的网站上,当我单击按钮时,页面向下移动了大约1厘米,而不是向下移动到适当的div?

我已经添加了下面的所有代码,并且可以在上面的示例中使用。

此代码正在wordpress网站上使用。

谢谢

HTML

<section>
<a href="#" class="scroll-down" address="true"></a>
</section>

CSS

.scroll-down {
  opacity: 1;
  -webkit-transition: all .5s ease-in 3s;
  transition: all .5s ease-in 3s;
}

.scroll-down {
  position: absolute;
  bottom: 30px;
  left: 50%;
  margin-left: -16px;
  display: block;
  width: 32px;
  height: 32px;
  border: 2px solid #FFF;
  background-size: 14px auto;
  border-radius: 50%;
  z-index: 2;
  -webkit-animation: bounce 2s infinite 2s;
  animation: bounce 2s infinite 2s;
  -webkit-transition: all .2s ease-in;
  transition: all .2s ease-in;
}

.scroll-down:before {
    position: absolute;
    top: calc(50% - 8px);
    left: calc(50% - 6px);
    transform: rotate(-45deg);
    display: block;
    width: 12px;
    height: 12px;
    content: "";
    border: 2px solid white;
    border-width: 0px 0 2px 2px;
}

@keyframes bounce {
  0%,
  100%,
  20%,
  50%,
  80% {
    -webkit-transform: translateY(0);
    -ms-transform: translateY(0);
    transform: translateY(0);
  }
  40% {
    -webkit-transform: translateY(-10px);
    -ms-transform: translateY(-10px);
    transform: translateY(-10px);
  }
  60% {
    -webkit-transform: translateY(-5px);
    -ms-transform: translateY(-5px);
    transform: translateY(-5px);
  }
}

JS

$(function() {
    $('.scroll-down').click (function() {
      $('html, body').animate({scrollTop: $('#div_outerfooter').offset().top }, 'slow');
      return false;
    });
  });

1 个答案:

答案 0 :(得分:0)

尝试一段时间以准备好文档内部

$(document).ready(function(){
    $(".scroll-down").click (function() {
          $('html, body').animate({scrollTop: $('section.ok').offset().top }, 'slow');
          return false;
        });
     });