<! DOCTYPE html> <Html> <Head> <Meta charset = "UTF-8"/> <Title> untitled document </title> <Style> Body, ul, li {margin: 0; padding: 0 ;} # Runs li {width: 80px; height: 80px; background: # 06c; List-style: none; margin: 10px; border: 1px solid #000; Filter: alpha (opacity = 30); opacity: 0.3 ;} </Style> <Script> Window. onload = function (){ Var runs = document. getElementById ("runs "); Var runs_li = runs. getElementsByTagName ("li "); Runs_li [0]. onmouseover = function (){ Startrun (this, "width", 300 ); } Runs_li [0]. onmouseout = function (){ Startrun (this, "width", 80 ); } Runs_li [1]. onmouseover = function (){ Startrun (this, "height", 300 ); } Runs_li [1]. onmouseout = function (){ Startrun (this, "height", 80 ); } Runs_li [2]. onmouseover = function (){ Startrun (this, "fontSize", 50 ); } Runs_li [2]. onmouseout = function (){ Startrun (this, "fontSize", 14 ); } Runs_li [3]. onmouseover = function (){ Startrun (this, "opacity", 100 ); } Runs_li [3]. onmouseout = function (){ Startrun (this, "opacity", 30 ); } } Function startrun (obj, attr, target ){ ClearInterval (obj. timer ); Obj. timer = setInterval (function (){ Var cur = 0; If (attr = "opacity "){ Cur = Math. round (parseFloat (getstyle (obj, attr) * 100 ); } Else { Cur = parseInt (getstyle (obj, attr )); } Var speed = (target-cur)/8; Speed = speed> 0? Math. ceil (speed): Math. floor (speed ); If (cur = target ){ ClearInterval (obj. timer ); } Else { If (attr = "opacity "){ Obj. style. filter = 'Alpha (opacity = '+ (cur + speed) + ')'; Obj. style. opacity = (cur + speed)/100; } Else { Obj. style [attr] = cur + speed + "px "; } } }, 30 ); } Function getstyle (obj, name ){ If (obj. currentStyle ){ Return obj. currentStyle [name]; } Else { Return getComputedStyle (obj, false) [name]; } } </Script> </Head> <Body> <Ul id = "runs"> <Li style = "top: 0"> 1 </li> <Li style = "top: 90px;"> 2 </li> <Li style = "top: 180px;"> 3 </li> <Li style = "top: 270px;"> 4 </li> </Ul> </Body> </Html> |