As always , Thanks for your Help…
This is the ‘watch it run’ page :
https://vmars.us/Guitar/Guitar-1-Circle-Gray-Move-OnClick-Image.html
I am trying to make " img id=“image01” not-draggable .
Unfortunately in trying to do that , I also make ‘circle 1’ not-draggable .
I am trying to cancel the ‘drag’ in the js .
I mark all 7 of my changes with a “//vm” to make them easy to find .
Here is my code :
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
<title>https://vmars.us/Guitar/Guitar-1-Circle-Gray-Move-OnClick-Image.html
</title>
<style>
body {
margin: 20px;
}
#container {
width: 100%;
height: 450px;
background-color: #DCDCDC;
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
border-radius: 7px;
touch-action: none;
counter-reset: itemCount;
}
.item {
display: inline-block;
border-radius: 50%;
touch-action: none;
user-select: none;
counter-increment: itemCount;
content: 'count' + itemCount;
width: 32px;
height: 32px;
background-color: #F5F5F5; // whitesmoke
font-family: Arial, Helvetica, sans-serif;
text-align:center;
font-size:28px;
}
#p1 {
position: absolute;
left: 50px;
width: 90%;
border-style: solid;
}
.item:active {
opacity: .75;
}
.item:hover {
cursor: pointer;
}
h1 {
margin-bottom: 10px;
}
</style>
<script>
</script>
</head>
<body>
<!-- -->
<div id="outerContainer">
<div id="container">
<div style=" position: absolute; right: 200; top: 50px; text-align: center; display: inline; ">
<div class="item" class="one" >1</div>
</div>
<br>
<div id="img1Div"; style="width: 100%;" >
<br>
<!-- <table style="text-align: center; width: 100%;" border="1" cellpadding="2" cellspacing="2"> -->
<p id="p2"; style="width: 100%;" >
<img id="image01" src="Fretboard-Table-Image-624x114.png" alt="Fretboard-Table-Image-624x114.png" width: 600px; height: 400px;>
</p>
</div>
</div> <!-- id="container" -->
<br>
<div>
<p contenteditable ="true" id="p1" style=" height: 100px; position: absolute; display: block;
position: absolute; bottom: 10px;" >Notes:
</p>
</div>
</div> <!-- id="outerContainer -->
<script>
var container = document.querySelector("#container");
var activeItem = null;
var activeItemKeep = null;
var active = false;
container.addEventListener("touchstart", dragStart, false);
container.addEventListener("touchend", dragEnd, false);
container.addEventListener("touchmove", drag, false);
container.addEventListener("mousedown", dragStart, false);
container.addEventListener("mouseup", dragEnd, false);
container.addEventListener("mousemove", drag, false);
function dragStart(e) {
if (e.target !== e.currentTarget) {
active = true;
// this is the item we are interacting with
// check if item is HTMLImageElement //vm
activeItem = e.target;
activeItemKeep = activeItem;
console.log(activeItem); //vm
// alert(activeItem); //vm
if (activeItemKeep = "HTMLImageElement") {return; } //vm
if (activeItem !== null) {
if (!activeItem.xOffset) {
activeItem.xOffset = 0;
}
if (!activeItem.yOffset) {
activeItem.yOffset = 0;
}
if (e.type === "touchstart") {
activeItem.initialX = e.touches[0].clientX - activeItem.xOffset;
activeItem.initialY = e.touches[0].clientY - activeItem.yOffset;
} else {
console.log("Dragging something!");
activeItem.initialX = e.clientX - activeItem.xOffset;
activeItem.initialY = e.clientY - activeItem.yOffset;
}
}
}
}
function dragEnd(e) {
if (activeItemKeep = "HTMLImageElement") {return; } //vm
if (activeItem !== null) {
activeItem.initialX = activeItem.currentX;
activeItem.initialY = activeItem.currentY;
}
active = false;
activeItem = null;
}
function drag(e) {
if (activeItemKeep = "HTMLImageElement") {return; } //vm
if (active) {
if (e.type === "touchmove") {
e.preventDefault();
activeItem.currentX = e.touches[0].clientX - activeItem.initialX;
activeItem.currentY = e.touches[0].clientY - activeItem.initialY;
} else {
activeItem.currentX = e.clientX - activeItem.initialX;
activeItem.currentY = e.clientY - activeItem.initialY;
}
activeItem.xOffset = activeItem.currentX;
activeItem.yOffset = activeItem.currentY;
setTranslate(activeItem.currentX, activeItem.currentY, activeItem);
}
}
function setTranslate(xPos, yPos, el) {
if (activeItemKeep = "HTMLImageElement") {return; } //vm
el.style.transform = "translate3d(" + xPos + "px, " + yPos + "px, 0)";
}
</script>
</body>
</html>