要让谷歌浏览器实现此特效怎么办呢,这个特效我测试了只能用IE打开。
老师讲的这个方法chrome不支持怎么办,现在很少人用IE的。
老师讲的这个方法chrome不支持怎么办,现在很少人用IE的。
2016-11-13
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>5</title>
<style type="text/css">
ul li{
list-style: none;
}
ul li{
width: 200px;
height: 100px;
background-color: yellow;
margin-bottom: 20px;
border:4px solid #DD5566;
}
</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);
}
}
}
function getStyle(obj,attr){
if (obj.currentStyle) {
return obj.currentStyle[attr];
}
else{
return getComputedStyle(obj,false);
}
}
//var timer = null;
function startMove(obj,iTarget){
clearInterval(obj.timer);
obj.timer = setInterval(function(){
var opg = parseInt(getStyle(obj,'width'));
var speed = (iTarget-opg)/8;
speed = (speed >0)?Math.ceil(speed):Math.floor(speed);
if (opg == iTarget) {
clearInterval(obj.timer);
}
else{
obj.style.['width'] = opg+speed+'px';
}
},30)
}
</script>
</head>
<body>
<ul>
<li>
</li>
<li>
</li>
<li>
</li>
</ul>
</body>
</html>
举报