When i drag the right part of uploaded image in mask1 , than uploaded image in mask2 is dragging, but that should't happen....
Here is video link
Also if i upload image only in mask 1 and try to drag, the image will disappear , but if i upload images in both masks, than image will not disappear
Codepen : https://codepen.io/kidsdial/pen/PVJQrz
<input type="file" id="fileupa" />
<input type="file" id="fileupb" />
<div class="container">
<div class="minaimg masked-imga" ondragover="onDragOver(event)"ondragover="onDragOver(event)" >
<div draggable="true" ondragstart="onDragStart(event)" id="uploadedImg">
<div class="minaimga">
<img id="target_imga" alt="">
<div></div>
</div>
</div>
</div>
<div class="minaimg masked-imgb" ondragover="onDragOverSec(event)"ondragover="onDragOver(event)" >
<div draggable="true" ondragstart="onDragStart(event)" id="uploadedImg2">
<div class="minaimgb">
<img id="target_imgb" alt="">
<div></div>
</div>
</div>
</div>
</div>
<style>
.container {
border: 1px solid #DDDDDD;
width: 612px;
height: 612px;
position:relative;
background:red;
}
.masked-imga
{
-webkit-mask-image: url(http://139.59.24.243/ecom1/site/test/images/heart1.png);
mask-image: url(http://139.59.24.243/ecom1/site/test/images/heart1.png);
-webkit-mask-position: center center;
mask-position: center center;
-webkit-mask-repeat: no-repeat;
mask-repeat: no-repeat;
width: 259px;
height: 278px;
position: absolute;
top: 221px;
left: 23px;
}
.masked-imgb
{
-webkit-mask-image: url(http://139.59.24.243/ecom1/site/test/images/heart2.png);
mask-image: url(http://139.59.24.243/ecom1/site/test/images/heart2.png);
-webkit-mask-position: center center;
mask-position: center center;
-webkit-mask-repeat: no-repeat;
mask-repeat: no-repeat;
width: 416px;
height: 388px;
position: absolute;
top: 111px;
left: 173px;
}
.minaimga
{
display: block;
background-color: white;
height: 278px;
}
.minaimgb
{
display: block;
background-color: white;
height: 388px;
}
</style>
<script>
fileupa.onchange = e => {
target_imga.src = URL.createObjectURL(fileupa.files[0]);
}
fileupb.onchange = e => {
target_imgb.src = URL.createObjectURL(fileupb.files[0]);
}
let prevX = 0, prevY = 0,translateX = 0, translateY = 0, scale = 1, zoomFactor = 0.1;
function onDragStart(evt) {
if (evt.dataTransfer && evt.dataTransfer.setDragImage) {
evt.dataTransfer.setDragImage(evt.target.nextElementSibling, 0, 0);
}
prevX = evt.clientX;
prevY = evt.clientY;
}
function onDragOver(evt) {
translateX += evt.clientX - prevX;
translateY += evt.clientY - prevY;
prevX = evt.clientX;
prevY = evt.clientY;
updateStyle();
}
function updateStyle()
{
let transform = "translate(" +translateX+ "px, "+ translateY + "px) scale("+scale+")";
if(document.querySelector('#uploadedImg img'))
document.querySelector('#uploadedImg img').style.transform = transform;
}
function onDragOverSec(evt) {
translateX += evt.clientX - prevX;
translateY += evt.clientY - prevY;
prevX = evt.clientX;
prevY = evt.clientY;
updateStyleSec();
}
function updateStyleSec()
{
let transform = "translate(" +translateX+ "px, "+ translateY + "px) scale("+scale+")";
if(document.querySelector('#uploadedImg2 img'))
document.querySelector('#uploadedImg2 img').style.transform = transform;
}
</script>
Edit
Is it because those two images overlapped horizontally & in vertically?
from Dragging one image makes other image to drag
No comments:
Post a Comment