<!DOCTYPE?html>
<html>
????<head>
????????<meta?charset="utf-8">
????????<title>多物體動(dòng)畫(huà)+獲取樣式2</title>
????????<style>
????????????ul,li{list-style:?none;}
????????????ul?li{width:?200px;height:?100px;background-color:?yellow;margin-bottom:?20px;
??????????????????border:10px?solid?#0000FF;}
????????</style>
????????<script>
????????????window.onload=function(){
????????????var?Li1=?document.getElementById('li1');
????????????var?Li2=?document.getElementById('li2');
????????????Li1.onmouseover=function(){
????????????????startMove(this,'height',400);
????????????}
????????????Li1.onmouseout=function(){
????????????????startMove(this,'height',100);
????????????}
????????????Li2.onmouseover=function(){
????????????????startMove(this,'width',400);
????????????}
????????????Li2.onmouseout=function(){
????????????????startMove(this,'width',200);
????????????}???
??????????}
????????????function?getStyle(obj,attr){??/*此函數(shù)用來(lái)獲取樣式*///可以改變寬高、背景屬性、字號(hào)屬性、邊框?qū)傩缘鹊????????????????if(obj.currentStyle){
???????????????????return?obj.currentStyle[attr];/*currentStyle針對(duì)IE*/
???????????????}
???????????????else{
???????????????????return?getComputedStyle(obj,false)[attr];/*getComputedStyle針對(duì)Firefox*/
???????????????}
???????????}
//????????????var?timer=null;
????????????function?startMove(obj,attr,iTarget){
????????????????clearInterval(obj.timer);
????????????????obj.timer=setInterval(function(){
????????????????????var?icur?=?parseInt(getStyle(obj,attr));
????????????????????var?speed=(iTarget-icur)/8;
????????????????????speed?=?speed>0?Math.ceil(speed):Math.floor(speed);
????????????????????if(icur==iTarget){
????????????????????????clearInterval(obj.timer);
????????????????????}
????????????????????else{
????????????????????????obj.style.[attr]=icur+speed+'px';
????????????????????}
????????????????},30)
????????????}
????????</script>
????</head>
????<body>
????????<ul>
????????????<li?id='li1'></li>
????????????<li?id='li2'>?</li>
????????</ul>
????</body>
</html>
2016-05-15
我也有一樣的問(wèn)題,沒(méi)有觸發(fā)startMove函數(shù),不是“.”的問(wèn)題,親,要是解決了,可以告訴我一下嗎
2015-11-20
48行多了一個(gè) .?