Betsey
2016-02-19 16:11
<!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>
// aLi[i].alpha=30 不要注释掉
<!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>
这样也运行不正确。。。。。。求指导
JS动画效果
113924 学习 · 1443 问题
相似问题