Home>
Friends, I'm writing a small application, I'm trying to implement so that when you hover (drag) a div element over another div element, the second one is colored. The problem is that it is not possible to track the event of the transfer of one element to another.
HTML
<div class="places"> <!--<p class="name">Canvas
p> --> <div class="place" data-id="11"></div> <div class="place" data-id="12"></div> <div class="place" data-id="13"></div> <div class="place" data-id="14"></div> <div class="place" data-id="15"></div> <div class="place" data-id="16"></div> <div class="place" data-id="17"></div> <div class="place" data-id="18"></div> <div class="place" data-id="21"></div> <div class="place" data-id="22"></div> <div class="place" data-id="23"></div> <div class="place" data-id="24"></div> <div class="place" data-id="25"></div> <div class="place" data-id="26"></div> <div class="place" data-id="27"></div> <div class="place" data-id="28"></div> <div class="place" data-id="31"></div> <div class="place" data-id="32"></div> <div class="place" data-id="33"></div> <div class="place" data-id="34"></div> <div class="place" data-id="35"></div> <div class="place" data-id="36"></div> <div class="place" data-id="37"></div> <div class="place" data-id="38"></div> <div class="place" data-id="41"></div> <div class="place" data-id="42"></div> <div class="place" data-id="43"></div> <div class="place" data-id="44"></div> <div class="place" data-id="45"></div> <div class="place" data-id="46"></div> <div class="place" data-id="47"></div> <div class="place" data-id="48"></div> </div>
JavaScript
const places= document.querySelectorAll('.place');
places.forEach(place=> {
const shape= document.querySelector('.shape');
place.addEventListener('mousedown', ()=> {
shape.addEventListener('dragstart', (event)=> {
//console.log('dragstart');
console.log(place.dataset.id);
});
shape.addEventListener('dragend', (event)=> {
//console.log('dragend');
console.log(place.dataset.id);
});
});
where is your shape created? does it exist in html? this is not visible in the code.
DraKoan2022-01-22 22:00:14Related questions
- javascript : Block scrolling by clicking on the arrows
- javascript : Regex how to parse a string
- javascript : not working innerHTML in setInterval and setTimeout + setTimeout in setInterval
- javascript slider thumbnail
- javascript : Display a specific line and position of HTML in another file
- javascript : When you click the button does not show the picture?
- javascript : My code is not displayed on the site, there are no errors
- javascript : Why is canvas not drawing?
- javascript : How to connect JS with imports so that an object is defined in body.onload?
- javascript : js code execution protection
shape is the div I'm dragging onto the other one
ANDR2022-01-22 22:00:14