实现向左滚动时受限于父盒子大小,两个UL不能在一行,怎么处理,代码如下
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
*{margin: 0;padding: 0;}
#box{width: 300px;height: 300px;background: #eee;margin:100px;overflow: hidden;}
ul{list-style: none;width: 400px;height: 300px;background: #aaa;float: left;}
a{text-decoration: none;color: #333;display: block;height: 30px;line-height: 40px;width: 200px;}
</style>
</head>
<body>
<div id="box">
<ul id="content">
<li><a href="#">1新闻内容</a></li>
<li><a href="#">2新闻内容</a></li>
<li><a href="#">3新闻内容</a></li>
<li><a href="#">4新闻内容</a></li>
<li><a href="#">5新闻内容</a></li>
<li><a href="#">6新闻内容</a></li>
<li><a href="#">7新闻内容</a></li>
<li><a href="#">8新闻内容</a></li>
<li><a href="#">9新闻内容</a></li>
<li><a href="#">10新闻内容</a></li>
</ul>
<ul id="content2"></ul>
</div>
<script>
window.onload=function () {
var oBox=document.getElementById('box');
var ct1=document.getElementById('content');
var ct2=document.getElementById('content2');
ct2.innerHTML=ct1.innerHTML;
var myScroll=setInterval(scrollUp,50)
oBox.onmouseover=function () {
clearInterval(myScroll);
}
oBox.onmouseout=function () {
myScroll=setInterval(scrollUp,50)
}
function scrollUp() {if (oBox.scrollLeft>=ct1.offsetLeft) {oBox.scrollLeft=0}else{(oBox.scrollLeft++)}}
}
</script>
</body>
</html>