為什么 只有一個屬性好使
<!DOCTYPE html>
<html>
<head>
? ? <meta charset="UTF-8">
? ? <title>Document</title>
? ? <link rel="stylesheet" href="css/master.css">
</head>
<body>
? ?<script>
? ? ?window.onload=function(){
? ? ? ? ?var ali = document.getElementsByTagName("li");
? ? ? ? ?for(var i= 0;i<ali.length;i++){
? ? ? ? ? ? ?ali[i].timer=null
? ? ? ? ? ? ?ali[i].onmouseover=function(){
? ? ? ? ? ? ? ? ?startMove(this,'height',400);
? ? ? ? ? ? ?}
? ? ? ? ? ? ?ali[i].onmouseout=function(){
? ? ? ? ? ? ? ? ?startMove(this,'height',100);
? ? ? ? ? ? ?}
? ? ? ? ? ? ?ali[i].onmouseover=function(){
? ? ? ? ? ? ? ? ?startMove(this,'width',400);
? ? ? ? ? ? ?}
? ? ? ? ? ? ?ali[i].onmouseout=function(){
? ? ? ? ? ? ? ? ?startMove(this,'width',200);
? ? ? ? ? ? ?}
? ? ? ? ?}
? ? ?}
// ? ? var timer = null
? ? ?function startMove(obj,attr,iTarget){
? ? ? ? ?clearInterval(obj.timer);
? ? ? ? ?obj.timer=setInterval(function(){
? ? ? ? ? ? ?var icor = ?parseInt(getStyle(obj,attr));
? ? ? ? ? ? ?var speed =(iTarget-icor)/8
? ? ? ? ? ? ?speed=speed>0?Math.ceil(speed):Math.floor(speed)
? ? ? ? ? ? ? ? if(icor==iTarget){
? ? ? ? ? ? ? ? ? ? clearInterval(obj.timer);
? ? ? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? ? ? obj.style[attr]=icor+speed+"px";
? ? ? ? ? ? ? ? ?// ? obj.style.fontSize=parseInt(getStyle(obj,"fontSize"))+speed+"px";
? ? ? ? ? ? ? ? }
? ? ? ? ?},30)
? ? ? ? ?
? ? ?}
? ? ?function getStyle(obj,attr){
? ? ? ? ? ?if(obj.currentsyle){
? ? ? ? ? ? ? ?return obj.currentsyle[attr]; ?//針對ie瀏覽器
? ? ? ? ? ?}else{
? ? ? ? ? ? ? ?return getComputedStyle(obj,false)[attr]; ?//針對firefox瀏覽器
? ? ? ? ? ?}
? ? ? ?}
? ?</script>
? ? <script>
? ? </script>
? ? <ul>
? ? ? ? <li>1111111</li>
<!--
? ? ? ? <li>11111</li>
? ? ? ? <li>11111</li>
-->
? ? </ul>
</body>
</html>
2016-06-28
ali[i].onmouseover=function(){
? ? ? ? ? ? ? ? ?startMove(this,'height',400);
? ? ? ? ? ? ?}
和
?ali[i].onmouseover=function(){
? ? ? ? ? ? ? ? ?startMove(this,'width',400);
? ? ? ? ? ? ?}
是同一個對象,它只能按順序執(zhí)行,不能同時執(zhí)行,因此忽略了width
2016-06-23
var ali = document.getElementsByTagName("li") 因為你獲取了一個變量屬性,