求幫助,同步運動用json替換沒有反應,無錯誤提醒,那里錯了?
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
body,ul,li{
margin: 0;
padding:0;
}
ul,li{
list-style: none;
}
ul li{
width: 200px;
height: 100px;
background: yellow;
border:4px solid #000000;
filter: alpha(opacity:30);
opacity: 0.3;
}
</style>
<script src="js/move.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
window.onload = function(){
var oLi = document.getElementById('li1');
oLi.onmouseover = function(){
starMove(oLi,{width:400,height:200});
}
// oLi.onmouseout = function(){
// starMove(oLi,'width',200);
// }
}
</script>
</head>
<body>
<ul>
<li id="li1"></li>
</ul>
</body>
</html>
//移動函數(shù)1 // starMove(obj,{attr1:iTarget1,attr2:iTarget2},fn); function?starMove(obj,json,fn){ clearInterval(obj.timer);?//清除定時器,避免重復生成多個定時器 obj.timer?=?setInterval(function(){ for(var?attr?in?json){ var?icur?=?0; if(attr?=='opacity'){ //round()?四舍五入 icur?=?Math.round(parseFloat(getStyle(obj,attr))*100); }else{ icur?=?parseInt(getStyle(obj,attr)); } var?speed?=?(json[attr]-icur)/8; speed?=?speed>0?Math.ceil(speed):Math.floor(speed); if(icur?==?json[attr]){ clearInterval(obj.timer); if(fn){ fn(); } }else{ if(attr?==?'opacity'){ //IE obj.style.filter?=?'alpha(opacity:'+(icur+speed)+')'; //火狐 obj.style.opacity?=?(icur+speed)/100; }else{ obj.style[attr]?=?icur+speed+'px'; } } } },30) } /*獲取樣式函數(shù)*/ function?getStyle(obj,attr){ if?(obj.currentStyle)?{ return?obj.currentStyle[attr]; }?else{ return?getComputedStyle(obj,false)[attr]; } }
2017-02-27
引入外部js文件的時候不需要?charset="utf-8",這是<meta>中用來說明編碼方式的