gpt4 book ai didi

css - 在 css 中单击时平滑滚动到特定的 div

转载 作者:太空宇宙 更新时间:2023-11-03 22:26:46 24 4
gpt4 key购买 nike

我正在尝试制作一个按钮,如果您单击它,它会使用 css 平滑地向下滚动到页面上的特定 div! (没有 JS 或 jquery)。例如:http://jsfiddle.net/YYPKM/3/我无法理解给出滚动平滑的代码到底是什么?我的代码:HTML:

<html>
<head>
<head>
<ul class="actions">
<li><a href="#description" class="button" id="cn">Continue</a></li>
</ul>
<section id="description">
<h2 style="font-weight: 700; font-size: 1.5em; margin-top: 2em;">Description</h2>
<section id="descr">
<div class="image desc"><img src="https://cdn.lynda.com/course/439683/439683-636441077028502313-16x9.jpg" width="800" height="550" title="Our company">
</div>
<div class="desc">
<h2>About Company</h2>
<p>Sometimes the mouse, but now it was the makeup of chocolate sauce ante powerful protein manufacturing sad sauce through a gateway.</p>
</div>
</section>
</section>
</html>

我的CSS:

/* Button */
.button {
background: #ffff00;
color: #000;
border-radius: 4px;
border: 0;
display: inline-block;
font-weight: 700;
height: 2.95em;
line-height: 3em;
padding: 0 1.5em;
text-decoration: none;
text-align: center;
margin-top: 1em;
}
#descr {
display: flex;
height: 90vh;
}
#descr .desc {
padding: 3.5em 0 1.5em 0;
padding-left: 2em;
padding-right: 2em;
background: #afdeed;
width: 50%;
}
.image.desc img {
text-align: center;
box-shadow: 5px 5px 20px;
}
.image.desc img {
animation: move 2s ease-in-out infinite;
animation-direction: alternate-reverse;
}
@-webkit-keyframes move {
0% {
transform: translate(0);
}
100% {
transform: translate(2.5em);
}
}
.image.desc:hover img {
animation: rotate 2s ease-in-out infinite;
animation-direction: alternate-reverse;
}

@-webkit-keyframes rotate {
0% {
transform: translate(-5em);
}
25% {
transform: rotate(20deg);
}
50% {
transform: translate(5em);
}
75% {
transform: rotate(-20deg);
}
}

我希望如果按钮被点击,它会平滑地滚动到下一个 div!

最佳答案

您可能已经做到了,但对于正在寻找简单答案的您来说,这里有一个更简单的解决方案。

html {
scroll-behavior: smooth;
}

关于css - 在 css 中单击时平滑滚动到特定的 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50682483/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com