Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize div Color Block drag recording by js

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Today, I will talk to you about js how to achieve div color block drag recording, many people may not know much about it. In order to make you understand better, the editor summed up the following content for you. I hope you can get something according to this article.

An example is given to share the specific code for js to realize p-color block drag recording. The specific contents are as follows.

Description:

Implement a p50 color block, drag it to generate a track, and when you release it, the p will repeat the path you just dragged.

Effect:

Code:

Title

P {width: 50px; height: 50px; background-color: deepskyblue; position: absolute; border: 2px solid # 656565;}

Var elem

Var state=0

/ / the current state is initially 0m / m-drag recording 1m / m-playback 2

Var arr= []; / / an array of our walking paths

Var list= []; / / an array of our walking paths

Var index=0; init (); function init () {elem=document.querySelector ("p")

Method.dragElem (elem)

Elem.addEventListener ("mousedown", mouseHandler)

Elem.addEventListener ("mouseup", mouseHandler)

SetInterval (animation,16);} function mouseHandler (e) {

/ / the current state is initially 0m / m-drag recording 1m / m-playback 2

If (e.typewritten examples = "mousedown") {

/ / Mouse press

State=1;} else if (e.typewritten examples = "mouseup") {

/ / Mouse up

CreateElemShadow ()

State=2

}

}

Function createElemShadow () {

Var bool=false

If (list.length===0) bool=true

For (var ionome0 / ionomarr.futhmur1) {

State=0; return;} * /

Index++

Var point=arr [index]

If (point) {

Elem.style.left=point.x+ "px"

Elem.style.top=point.y+ "px"

Elem.style.backgroundColor=Method.pColor ();}

Var bool=false

For (var iTuno Bandi)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report