JS给元素添加自定义hover函数

  • Post author:
  • Post category:其他


<!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" />
	<meta name="viewport" content="width=device-width, initial-scale=1,user-scalable=no" charset="utf-8">
	<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
	<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
	<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
	<title>无标题文档</title>
	<script type="text/javascript">
	$(document).ready(function(){
  		$("#demo1").hover(function(){
	 		$("#demo1").css("top","20px");
			$("#demo1").css("left","20px");
			
	  	},function(){
			$("#demo1").css("top","0px");
		    $("#demo1").css("left","0px");

		});
  	});
</script>
</head>
<body>
 <div>
 	<div style="position: relative; width:240px; height:240px; border:1px solid #CCC; padding:20px;" id="demo1">
 		<div  style="width:200px; height:200px; background-color:#096;" >
    		111
    	</div>
    </div>
 	<div style="width:200px; height:200px; background-color:#096;" id="demo2">
    	222
    </div>
 </div>
</body>
</html>



版权声明:本文为y_bccl27原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。