第一个li
.不执行margin-left
、剩下都执行margin-left
.list-title li+li {
margin-left: 100px;
}
Jquery获取offsetHeight
javascript:
window.document.getElementById('MainColumn').offsetHeight
jquery:
$('#id').get(0).offsetHeight
图片仅供参考
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style media="screen">
* {
margin: 0; padding: 0;
box-sizing: border-box;
}
img {
display: block; /* 块级别消除img距离 */
}
#list-box {
width: 1198px;
height: 360px;
border: 1px solid #32D2A6;
margin: 0px auto;
position: relative;
overflow: hidden;
}
#list-content {
width: 1198px;
overflow: hidden;
position: absolute;
top: 0px;
left: 0;
}
#list-content li {
list-style: none;
height: 60px;
}
</style>
</head>
<body>
<div class="list-box" id="list-box">
<ul class="list-content" id="list-content">
<li><img src="https://www.dummyimage.com/1198x60/111/fff" alt=""></li>
<li><img src="https://www.dummyimage.com/1198x60/333/fff" alt=""></li>
<li><img src="https://www.dummyimage.com/1198x60/555/fff" alt=""></li>
<li><img src="https://www.dummyimage.com/1198x60/777/fff" alt=""></li>
<li><img src="https://www.dummyimage.com/1198x60/999/fff" alt=""></li>
<li><img src="https://www.dummyimage.com/1198x60/aaa/fff" alt=""></li>
</ul>
</div>
<script type="text/javascript" src="https://cdn.bootcss.com/jquery/1.12.4/jquery.js"></script>
<script type="text/javascript">
var $listCon = $('#list-content');
var oBox = document.getElementById("list-box");
var timer = null;
// 猫腻图
$listCon.children('li:lt(6)').clone().appendTo($listCon);
moveTop(); // 进入页面自动向上滚动
var oTop = $listCon.get(0).offsetTop; // 0 ,参考下面的图
function moveTop() {
clearInterval( timer );
timer = setInterval( function () { // 定时器函数
oTop -= 1;
if ( oTop <= -$listCon.get(0).offsetHeight / 2 ) {//获取ul的总高度
oTop = 0;
}
$listCon.css('top', oTop + 'px');
},30);
oBox.onmouseover = function(){
clearInterval( timer );
}
oBox.onmouseout = function(){
moveTop();
}
}
console.log(oTop);
console.log($listCon.get(0).offsetHeight);
</script>
</body>
</html>