这里的timer是全局的变量吗?怎么没有声明,怎么不会报错
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title</title>
<style type="text/css">
* {
margin: 0;
padding: 0;
font: 12px '微软雅黑';
}
#smooth div {
float: left;
}
#smooth {
height: 200px;
width: 350px;
position: absolute;
left: -300px;
top: 100px;
}
#content {
background: #d3eff9;
height: 200px;
width: 300px;
}
#button {
height: 50px;
width: 25px;
background: #d3eff9;
cursor: pointer;
}
#button span {
display: block;
width: 12px;
margin: 8px auto;
}
#wrap {
height: 600px;
background: #3979d9;
}
</style>
</head>
<body>
<div id="wrap"></div>
<div id="smooth">
<div id="content"></div>
<div id="button"><span>分享</span></div>
</div>
<script type="text/javascript">
window.onload = function () {
var divL = document.getElementById('smooth'),
timer = null;
function smoothing(iTarget) {
clearInterval(timer);
var speed = 0;
// var l = divL.offsetLeft;
timer = setInterval(function () {
var l = divL.offsetLeft;
speed = (iTarget - l)/12;
speed = speed>0?Math.ceil(speed):Math.floor(speed);
if (l == iTarget) {
clearInterval(timer);
}
else {
l = l + speed;
divL.style.left = l + 'px';
/*console.log(l);
console.log(divL.offsetLeft);
console.log('speed:'+speed);*/
}
}, 30);
}
divL.onmouseover = function () {
smoothing(0);
}
divL.onmouseout = function () {
smoothing(-300);
}
}
</script>
</body>
</html> <!--问题:这里的timer变量哪来的啊,都没有声明啊???-->