定时器与拖拽——js

    科技2022-07-15  135

    定时器

    setTimeout 单次定时 第一个参数是匿名函数 第二参数是多少毫秒后执行 第三个函数是返回值(返回的是地址)clearTimeout() 清除定时器setInterval 多次定时 第一个参数是匿名函数 第二参数是多少毫秒后执行 第三个函数是返回值(返回的是地址)clearInterval() 清除定时器

    拖拽

    <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>拖拽效果</title> <style> #box{ width: 200px; height: 200px; background-color: black; position: relative; left:100px; } </style> </head> <body> <div id='box' οnmοusedοwn="mv(this)" > </div> <script> function mv(_this){ // console.log('我是鼠标按下事件') _this.οnmοusemοve=function(event){ console.log('我是移动事件') // console.log(event) // console.log(_this) _this.style.left = event.clientX-100+"px" _this.style.top = event.clientY-100+"px" } _this.οnmοuseup=function(){ _this.οnmοusemοve=null } } </script> </body> </html>
    Processed: 0.010, SQL: 8