我希望我的网站在单击网页中的向右箭头时侧向滚动。我制作了一个未完成的小脚本,但它没有按预期工作。在脚本中,该速率应每 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>