gpt4 book ai didi

Javascript 侧滚动条

转载 作者:太空宇宙 更新时间:2023-11-03 18:58:38 25 4
gpt4 key购买 nike

我希望我的网站在点击网页中的向右箭头时横向滚动。我制作了一个未完成的小脚本,但它没有按预期工作。在脚本中,速率应每 10 毫秒降低一次,从而导致网页向侧面滚动。稍后我将添加一个功能,以在达到所需的边距时停止滚动。这是代码:

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<style type="text/css">
body {
background-image:url(ios-linen.jpg);
overflow:hidden;
}
div.length {
width:10000px;
}
div.container {
position:fixed;
top:50%;
left:50%;
margin-top:-300px;
margin-left:-450px;
}
div.content {
display:inline-block;
height:600px;
width:900px;
background-color:#CCC;
opacity:0.3;
border-radius:20px;
position:absolute;
z-index:0;
box-shadow:white 2px 2px 70px;
}
div.info {
z-index:1;
position:inherit;
width:870px;
padding-left:20px;
padding-top:10px;
}
div.arrow {
color:white;
font-size:400px;
font-weight:bold;
position:fixed;
opacity:0.5;
-moz-transition:all .5s;
-webkit-transition:all .5s;
transition:all .5s;
}
div.arrow:hover {
opacity:1;
}
#left {
top:50%;
margin-top:-200px;
left:5%;
}
#right {
top:50%;
margin-top:-200px;
left:80%;
}
</style>
<script type="text/javascript">
function right() {
var rate = 0;
setInterval(function() {
document.getElementById('length').style.marginLeft += rate;
rate--;
}, 10);
}
</script>
</head>

<body bgcolor="black">
<div class="length" id="length">
<div class="arrow" id="left">
<
</div>
<div class="arrow" id="right" onclick="right()">
>
</div>
<div class="container">
<div class="content">
</div>
<div class="info">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean est orci, tempus id lobortis vel, euismod sed eros. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed vehicula urna ut mi laoreet malesuada. Nunc semper, nisl vel semper commodo, sem quam laoreet magna, vel tristique orci tellus sit amet sem. Cras tincidunt urna sed justo consequat porta. Pellentesque commodo lacinia est, a dapibus odio venenatis ut. Vestibulum eget luctus turpis. Morbi libero urna, laoreet commodo euismod quis, aliquam in metus.
</div>
</div>
<div class="container" style="margin-left:1600px;">
<div class="content">
</div>
<div class="info">
Vivamus bibendum pretium enim quis faucibus. Etiam tempor dui varius nisi sagittis consectetur. Ut eget sapien ut metus consectetur hendrerit. Morbi lacinia porttitor nunc, rutrum ullamcorper arcu elementum quis. In eget nisi vel ante lacinia eleifend. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam leo odio, accumsan nec rhoncus sit amet, viverra sed urna. Mauris consequat turpis sed risus ultrices pulvinar.
</div>
</div>
</div>
</body>
</html>

最佳答案

它看起来不滚动的原因是因为页面上的所有其他 DIV 都有 position:fixed; 包含的 DIV length 可能会移动,但是箭头和灰色背景不会通过更改 length 元素的填充而移动。

要验证这一点,请向 length DIV 添加一个“watch”并在控制台中检查它。

关于Javascript 侧滚动条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12803128/

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