A Pen by Akhil a.k.a Enforcer007 on CodePen.
Created
March 18, 2022 07:38
-
-
Save akhildevelops/c77960b17310072abc9fa15ea374a4b2 to your computer and use it in GitHub Desktop.
eYyJdWQ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body onload="onload()"> | |
<div class="main"> | |
<div> | |
Hello | |
</div> | |
<div class="centre"> | |
<div id="canvas"> | |
<div class="marker"></div> | |
<div id="second"> | |
</div> | |
<div id="first"> | |
</div> | |
<div id="third"> | |
<img class="noSelect" src="https://avatars.githubusercontent.com/u/6951100?s=40&v=4" alt="@Enforcer007"> | |
</div> | |
</div> | |
</div> | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function onload() { | |
const | |
class Box { | |
constructor(element) { | |
this.box = element; | |
this.handleMouseDown = this.handleMouseDown.bind(this); | |
this.handleMouseUp = this.handleMouseUp.bind(this); | |
this.handleMouseMove = this.handleMouseMove.bind(this); | |
} | |
handleMouseDown() { | |
this.box.style.cursor = "move"; | |
this.box.addEventListener("mouseup", this.handleMouseUp); | |
canvas.addEventListener("mousemove", this.handleMouseMove); | |
canvas.addEventListener("mouseout", this.handleMouseUp); | |
} | |
handleMouseUp() { | |
this.box.style.cursor = "default"; | |
canvas.removeEventListener("mousemove", this.handleMouseMove); | |
canvas.removeEventListener("mouseleave", this.handleMouseUp); | |
} | |
handleMouseMove(e) { | |
const boxRect = this.box.getBoundingClientRect(); | |
this.box.style.top = `${this.box.offsetTop + e.movementY}px`; | |
this.box.style.left = `${this.box.offsetLeft + e.movementX}px`; | |
} | |
init() { | |
this.box.addEventListener("mousedown", this.handleMouseDown); | |
} | |
} | |
elem = new Box(second); | |
elem2 = new Box(third); | |
elem2.init(); | |
elem.init(); | |
console.log(window.getComputedStyle(elem.box)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdnjs.cloudflare.com/ajax/libs/moveable/0.28.0/moveable.min.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
background-color: black; | |
color: wheat; | |
} | |
.centre { | |
display: flex; | |
justify-content: center; | |
} | |
#canvas { | |
position: relative; | |
border: 3px solid #734565; | |
width: 50%; | |
height: 300px; | |
overflow: hidden; | |
} | |
#first { | |
position: absolute; | |
width: 100px; | |
left: 10px; | |
top: 10px; | |
height: 200px; | |
border: 1px solid #ab7854; | |
background-color: blue; | |
} | |
#second { | |
position: absolute; | |
border: 1px solid #cd67ef; | |
width: 100px; | |
height: 100px; | |
left: 50px; | |
top: 50px; | |
background-color: green; | |
} | |
#third { | |
position: absolute; | |
left: 200px; | |
width: 200px; | |
} | |
img { | |
position: relative; | |
width: 100%; | |
height: 100%; | |
z-index: -1; | |
} | |
.noSelect { | |
-webkit-tap-highlight-color: transparent; | |
-webkit-touch-callout: none; | |
-webkit-user-select: none; | |
-khtml-user-select: none; | |
-moz-user-select: none; | |
-ms-user-select: none; | |
user-select: none; | |
} | |
.noSelect:focus { | |
outline: none !important; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment