gpt4 book ai didi

css - 平滑的 css 选框

转载 作者:行者123 更新时间:2023-11-28 05:38:06 25 4
gpt4 key购买 nike

我有一个 CSS 选框,它运行良好,但不是 100% 流畅。我可以编辑下面的代码以使其运行更流畅吗?

我尝试过不同的动画:marquee Xs linear infinite speeds,但没有成功。

<style>
/* Make it a marquee */
.marquee {
width: 100%;
margin: 0 auto;
white-space: nowrap;
overflow: hidden;
background-color: #000000;
bottom: 0px;
}

.marquee span {
display: inline-block;
padding-left: 100%;
text-indent: 0;
animation: marquee 15s linear infinite;
background-color: #000000;
color: white;
bottom: 0px;
}

/* Make it move */
@keyframes marquee {
0% { transform: translate(0, 0); }
100% { transform: translate(-100%, 0); }
}

/* Make it pretty */
.scroll {
padding-left: 1.5em;
position: fixed;
font: 50px 'Verdana';
bottom: 0px;
left: 0px;
height: 10%;
}
</style>

HTML

<p class="scroll marquee"><span id="scrolltext"></span></p>

最佳答案

将 id="marquee"添加到您的跨度中。从 css 中删除动画行并在代码末尾添加此 javascript:

var marqueePosition = 0;
var speed = 10; //smaller number means faster movement
var e = document.getElementById('marquee');
function moveMarquee() {
marqueePosition--;
if(marqueePosition < (-1*e.offsetWidth)) marqueePosition = 0;
e.style["-webkit-transform"] = "translate("+marqueePosition+"px, 0px)";
e.style["-moz-transform"] = "translate("+marqueePosition+"px, 0px)";
e.style["-ms-transform"] = "translate("+marqueePosition+"px, 0px)";
e.style["-o-transform"] = "translate("+marqueePosition+"px, 0px)";
e.style["transform"] = "translate("+marqueePosition+"px, 0px)";
window.setTimeout(function() {
requestAnimationFrame(moveMarquee);
}, speed);
}
moveMarquee();

关于css - 平滑的 css 选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38071808/

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