How to realize div Color Block drag recording by js
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)