Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize div Color Block drag recording by js

Shulou Source: shulou.com Published: 2022-06-02 09:15:41 09月29日 Update

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)

Tags: Color blocks content paths code arrays status mouse examples effects more knowledge articles industry information information channels tracks channels enter one support related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple MySQL OPPO Reno Docker Shulou Technology