為什么這個函數后面運行的那個函數先運行了
應該寬變寬之后跳出a,可是一開始就跳出a了
<!doctype?html>
<html?lang="en">
<head>
????<meta?charset="UTF-8">
????<title>任意屬性值2</title>
????<style?type="text/css">
????????body,div{??padding:0;margin:0;font:normal?12px?"微軟雅黑"}
????????div{
????????????width:200px;
????????????height:150px;
????????????background-color:?gold;
????????????top:20px;
????????????left:20px;
????????????filter:?alpha(opacity:30);
????????????opacity:?0.3;
????????????float:left;
????????????margin-left:20px
?}
????</style>
????<script?type="text/javascript">
????????window.onload=function()?{
????????????var?box?=?document.getElementById("box");
????????????????box.alpha=30;
????????????????box.timer=null;
????????????????box.onmouseover?=?function(){startMove(this,'width',300,alert("a"))};
????????};
????????function?startMove(obj,attr,target,fn){
????????????clearInterval(obj.timer);
????????????obj.timer=setInterval(
????????????????????function(){
????????????????????????var?icur=0;
????????????????????????if(attr=='opacity'){
????????????????????????????icur=Math.round(parseFloat(getStyle(obj,attr))*100)
????????????????????????}else{
????????????????????????????icur=?parseInt(getStyle(obj,attr));
????????????????????????}
????????????????????????var?speed=(target-icur)/8;
????????????????????????speed=speed>0?Math.ceil(speed):Math.floor(speed);
????????????????????????if(icur==target){
????????????????????????????clearInterval(obj.timer);
????????????????????????????if(fn){
????????????????????????????????fn()
????????????????????????????}
????????????????????????}else{
????????????????????????????if(attr=='opacity'){
????????????????????????????????obj.style.filter='alpha(opacity:'+(icur+speed)+')';
????????????????????????????????obj.style.opacity=(icur+speed)/100
?}else{
????????????????????????????????obj.style[attr]=icur+speed+'px'
?}
????????????????????????}
????????????????????},30)
????????}
????????function?getStyle(obj,attr){
????????????if(obj.currentStyle){
????????????????return?obj.currentStyle[attr];
????????????}else{
????????????????return?getComputedStyle(obj,false)[attr];
????????????}
????????}
????</script>
</head>
<body>
<div?id="box"></div>
</body>
</html>
2016-05-11
alert要用function(){}包裹起來
2016-05-11
你這個代碼好奇怪,即不像JS的外部文件
如果是寫框架,你還需要傳參吧