求教透明度里沒定義timer的問題
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標(biāo)題文檔</title>
<style>
*{margin:0;padding:0;
}
ul,li{
list-style:none;
}
ul li{
width:200px;
height:100px;
background:yellow;
margin-bottom:20px
}
</style>
<script>
window.onload=function(){
var onLi=document.getElementsByTagName('li');
? ?for(var i=0;i<onLi.length;i++){
? onLi[i].timer=null;
? onLi[i].onmouseover=function(){
? startmove(this,400);
? }
? onLi[i].onmouseout=function(){
? startmove(this,200);
? }
? }
}
function startmove(obj,iTarget){
clearInterval(obj.timer);
obj.timer=setInterval(function(){
var speed=(iTarget-obj.offsetWidth)/20;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if(obj.offsetWidth==iTarget){
clearInterval(obj.timer);
}else{
obj.style.width=obj.offsetWidth+speed+'px';
}
},30)
}
</script>
</head>
<body>
<ul>
<li></li>
<li></li>
<li></li>
</ul>
</body>
</html>
不是說每次在執(zhí)行功能函數(shù)startmove()前都要用timer=null;清除嗎? 但是老師在講的時候沒有添加也照常運行,是可以不用寫還是忘了寫。。。
2022-03-25
老師有問題啊那個首頁盡然居中了~~獲取ID為txt的classname,請確定是否設(shè)置的classname.
2017-08-02
按你的理解來說在onLi[i].timer=null已經(jīng)清除了,所以timer=null實際上加不加都可以
而我覺得timer=null是不需要的,因為這里根本不需要清零
2017-07-12
<script>
window.onload=function(){
var onLi=document.getElementsByTagName('li');
? ?for(var i=0;i<onLi.length;i++){
? onLi[i].timer=null;
? onLi[i].onmouseover=function(){
? startmove(this,400);
? }
? onLi[i].onmouseout=function(){
? startmove(this,200);
在前面是有這句的。我加了下劃線,你看下