JavaScript编程交流 加入小组

18个成员 23个话题 创建时间:2015-09-15

js鼠标经过div宽度增加代码

发表于06-06 343次查看

js鼠标经过div宽度增加代码,js鼠标经过div宽度加宽代码下载:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>js原生态鼠标经过div宽度加宽常用js代码下载_吾爱编程</title>
<style>
.div1 {
	width:100px;
	height:100px;
	margin:20px;
	background:#f60;
}
</style>
<script>
window.onload = function(){
	var oDiv = document.getElementsByTagName('div');
	for(var i=0 ; i<oDiv.length; i++){
		oDiv[i].timer = null; //给每个DIV加一个定时器
		oDiv[i].onmouseover = function(){
			starMove(this,600);
		};
		oDiv[i].onmouseout = function(){
			starMove(this,100);
			console.info(this.offsetWidth);
		};
	}	
}
//var timer = null ;
function starMove(obj,iTarget){
	clearInterval(obj.timer);
	obj.timer = setInterval(function(){
		speed = (iTarget - obj.offsetWidth)/6;
		speed = speed>0 ? Math.ceil(speed):Math.floor(speed);
		if(obj.offsetWidth == iTarget){
			clearInterval(obj.timer);
		}else{
			obj.style.width = obj.offsetWidth + speed + "px";	
		}
	},30);
}
</script>
</head>
<body>
<div class="div1"></div>
<div class="div1"></div>
<div class="div1"></div>
</body>
</html>

我学院网推荐学习:JS实现HTML5 Canvas图像数据和图片的互相转化

发表回复
你还没有登录,请先 登录或 注册!