【发布时间】:2019-01-04 11:08:16
【问题描述】:
我在键盘上看到了这段代码: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;
});
});
【问题讨论】:
-
请创建minimal reproducible example,事实上,这可能是由任何原因引起的。没有工作示例,任何人都可以猜测。
-
不,如果您不分享完整的相关代码,我们不知道。
-
寻求调试帮助的问题(“为什么这段代码不起作用?”)必须在问题本身中包含所需的行为、特定问题或错误以及重现它所需的最短代码 .
-
您的示例仍未完成,html 中没有 id 为“div_outerfooter”的元素。所以这个例子对调试你的代码没有帮助。
-
id div_outerfooter 在我页面的整个代码中。
标签: jquery html wordpress scroll scrolltop