I am uploading an image using an input tag and fileReader. I have made the image draggable using drag and drop API of angular material. Also, there are 2 divs. The following code shows it.
<input type="file" (change)="fileChange($event)" placeholder="Upload file" >
<img id="blah" [src]="url" alt="your image" cdkDrag/>
<div class="box1">
hi
</div>
<div class="box2">
hi
</div>
<div class="box3">
hi
</div>
My requirement is that, when I drag the image into one of the div boxes, the color of the div should change. Right now I am able to drag the image into the div boxes but how do I change the color of the div when the image is dragged on to it.
From the code provided, I have the following idea.
Steps:
document.querySelector('#blah').parentNode
const divNeeded = document.querySelector('#blah').parentNode
relatedStyle
, you can add it to divNeeded
by using .classList.add('relatedStyle')
.Example for the style in CSS file:
.relatedStyle{
background-color: blue
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.