<div class="bottom clearfix" id="bottom">
<div class="one" id="div1">
<img src="../images/smallpic.png">
<span class="span" id="sp1">
<strong class="s1">家装监理</strong>
<em class="s2">4大验收阶段 78项验收标准全程把关</em>
</span>
</div>
<div class="two" id="div2">
<img src="../images/smallpic.png">
<span class="span" id="sp2">
<strong class="s1">家装监理</strong>
<em class="s2">4大验收阶段 78项验收标准全程把关</em>
</span>
</div>
<div>
var sp1 = document.getElementById("sp1");
var sp2 = document.getElementById("sp2");
var div1 = document.getElementById("div1");
var div2 = document.getElementById("div2");
var bottom = document.getElementById("bottom");
var divs = bottom.getElementsByTagName("div");
var spans = bottom.getElementsByTagName("span");
var speed =-10;
var start =260;
var timer ;
var timerout;
for (var i = 0; i < divs.length; i++) {
// divs[i].index = i;
divs[i].onmouseover=function(num){
return function(){
if (timer) {
clearInterval(timer);
start=260;
};
timer = setInterval(function(){
start +=speed;
if (start<=0) {
start=0;
clearInterval(timer);
};
// console.log(this.index);
spans[num].style.top = start+"px";
},100)
}}(i)
};
for (var i = 0; i < divs.length; i++) {
divs.index = i;
divs[i].onmouseout = function(){
timerout = setInterval(function(){
**start = parseInt(spans[this.index].style.top);**
start -=speed;
spans[this.index].style.top = start+"px";
},100);
}
};
}
spans[this.index].style
中的这个 style 获取的是行内样式,你没有设置行内样式它就是undefined