为了账号安全,请及时绑定邮箱和手机立即绑定

这个代码里面什么地方错了啊?

<!DOCTYPE html>

<html>


<head>

<meta charset="UTF-8">

<title></title>

<style>

* {

margin: 0;

padding: 0;

}

ul {

list-style: none;

}

li {

width: 200px;

height: 100px;

background: yellow;

margin-bottom: 20px;

border: 1px solid #807A62;

}

</style>

<script type="text/javascript">

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, 400);

}

aLi[i].onmouseout = function() {

startMove(this, 200);

}

}

}

//var timer = null;


function startMove(obj, iTarget) {

clearInterval(obj.timer);

obj.timer = setInterval(function() {

var speed=(iTarget-obj.offsetWidth)/10;

speed=speed>0?Math.ceil(speed):Math.floor(speed);

if (obj.offsetWidth == iTarget) {

clearInterval(obj.timer);

} else {

obj.style.width = parseInt(getStyle(obj,'width'))+ speed + 'px';

}

}, 30)

}

function getStyle(obj,attr){

if(obj.currentStyle){

return obj.currentStyle[attr];

}else{

return obj.getComputedStyle(obj,false)[attr];

}

}


</script>

</head>


<body>

<ul>

<li></li>

<li></li>

<li></li>

</ul>

</body>


</html>


正在回答

2 回答

// aLi[i].alpha=30 不要注释掉

0 回复 有任何疑惑可以回复我~

<!DOCTYPE html>

<html>


<head>

<meta charset="UTF-8">

<title></title>

<style>

* {

margin: 0;

padding: 0;

}

ul {

list-style: none;

}

li {

width: 200px;

height: 100px;

background: yellow;

margin-bottom: 20px;

/*filter:alpha(opacity:30);*/

/*opacity: 0.3;*/

border: 1px solid #807A62;

}

</style>

<script type="text/javascript">

window.onload = function() {

var aLi = document.getElementsByTagName("li");

for (var i = 0; i < aLi.length; i++) {

aLi[i].timer=null;

// aLi[i].alpha=30

aLi[i].onmouseover = function() {

startMove(this, 400);

}

aLi[i].onmouseout = function() {

startMove(this, 200);

}

}

}

//var timer = null;


function startMove(obj, iTarget) {

clearInterval(obj.timer);

obj.timer = setInterval(function() {

var speed=(iTarget-parseInt(getStyle(obj,'width')))/10;

speed=speed>0?Math.ceil(speed):Math.floor(speed);

if (parseInt(getStyle(obj,'width')== iTarget) {

clearInterval(obj.timer);

} else {

obj.style.width = parseInt(getStyle(obj,'width'))+ speed + 'px';

// obj.alpha=obj.alpha+speed;

// obj.style.filter="alpha(opacity:"+obj.alpha+")";

// obj.style.opacity=obj.alpha/100;

}

}, 30)

}

function getStyle(obj,attr){

if(obj.currentStyle){

return obj.currentStyle[attr];

}else{

return obj.getComputedStyle(obj,false)[attr];

}

}


</script>

</head>


<body>

<ul>

<li></li>

<li></li>

<li></li>

</ul>

</body>


</html>

这样也运行不正确。。。。。。求指导

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

这个代码里面什么地方错了啊?

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信