為什么不行啊
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>加入樣式的多物體運(yùn)動</title>
<style type="text/css">
? ? #div1{
? ? ? ? ?width:200px;
? ? ? ? height:200px;
? ? ? ? background: #f00;
? ? ? ? border: 4px solid #ccc;
? ? }
</style>
<script>
? ? window.onload=function(){
? ? ? ? startmove();
? ? }
? ? function startmove(){
? ? ? ? setInterval(function(){
? ? ? ? ? ? var odiv=document.getElementById('div1');
? ? ? ? odiv.style.width=parseInt(getStyle(odiv,'width'))-1+'px';//parseint()的作用是解析一個字符串,并返回一個整數(shù)。
? ? },30)
? ? ? ??
? ? }
? ? function getStyle(obj,attr){
? ? ? ? if(obj.currentStyle){
? ? ? ? ? ? return obj.currentStyle[attr];//針對IE瀏覽器
? ? ? ? }
? ? ? ? else{
? ? ? ? ? ? return getComputedStyle(obj,false)[attr];//針對firefox瀏覽器。
? ? ? ? }
? ? }
</script>
<meta name="description" content="">
<meta name="keywords" content="">
<link href="" rel="stylesheet">
</head>
<body>
? ? <div id="div1" >
? ? ? ??
? ? </div>
</body>
</html>
2016-10-16
getstyle封裝方法兩個參數(shù)之間你用的是中文輸入法的“,”,改成英文輸入法“,”。