版权声明:进击的葱 https://blog.csdn.net/qlwangcong518/article/details/86505468
描述:
引入jquery的过程不叙述了,网上都有
这里实现的是点击div块做移动
效果:
实现:
注释部分是原来不用jquery的时候要写的代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="node_modules/[email protected]@jquery/dist/jquery.js"></script>
</head>
<body>
<div></div>
<script>
/*var div=document.querySelector("div");
Object.assign(div.style,{
width:"100px",
height:"100px",
backgroundColor:"red",
position:"absolute"
});
div.addEventListener("click",clickHandler);
function clickHandler(e) {
this.style.left=this.offsetLeft+2+'px';
}*/
$("div").css({
width:"100px",
height:"100px",
backgroundColor:"red",
position:"absolute"
}).on("click",function () {
$(this).css("left",this.offsetLeft+2+"px")
})
</script>
</body>
</html>