Pesquisar neste blog

14/12/2020

Trabalhando com Eventos em HTML #03

</html>
<!DOCTYPE html>
<html>

<head>
    <meta charset='UTF-8'>
    <title>Trabalhando com Eventos #03</title>
    <style>
        body {
            margin0;
            displayflex;
        }
        
        .esquerda {
            height100vh;
            width50%;
            background-colorcoral;
        }
        
        .direita {
            height100vh;
            width50%;
            background-colorcornflowerblue;
        }
        
        .item {
            bordersolid 5px black;
            background-colordarkgrey;
            colorwhite;
            height100px;
            font-size40px;
            margin10px;
            vertical-alignmiddle;
            text-aligncenter;
        }
    </style>
</head>

<body>
    <div class="esquerda" wm-dropzone>
        <div class="item">1</div>
        <div class="item">2</div>
        <div class="item">3</div>
        <div class="item">4</div>
    </div>
    <div class="direita" wm-dropzone></div>
    <script>
        const items = document.querySelectorAll('[wm-dropzone] .item')
        items.forEach((itemindex=> {
            item.draggable = true
            item.id = item.id || `draggable-item-${index}`
            item.ondragstart = e =>
                e.dataTransfer.setData('item-id'e.target.id)
        })

        const dropzones = document.querySelectorAll('[wm-dropzone]')
        dropzones.forEach(dropzone => {
            dropzone.ondragover = e => e.preventDefault()
            dropzone.ondrop = function(e) {
                const id = e.dataTransfer.getData('item-id')
                const item = document.getElementById(id)
                e.target.appendChild(item)
                //dropzone.appendChild(item)
            }
        })
    </script>
</body>

</html>





















</html>
<!DOCTYPE html>
<html>

<head>
    <meta charset='UTF-8'>
    <title>Trabalhando com Eventos #03</title>
    <style>
        body {
            margin0;
            displayflex;
        }
        
        .esquerda {
            height100vh;
            width50%;
            background-colorcoral;
        }
        
        .direita {
            height100vh;
            width50%;
            background-colorcornflowerblue;
        }
        
        .item {
            bordersolid 5px black;
            background-colordarkgrey;
            colorwhite;
            height100px;
            font-size40px;
            margin10px;
            vertical-alignmiddle;
            text-aligncenter;
        }
    </style>
</head>

<body>
    <div class="esquerda" wm-dropzone>
        <div class="item">1</div>
        <div class="item">2</div>
        <div class="item">3</div>
        <div class="item">4</div>
    </div>
    <div class="direita" wm-dropzone></div>
    <script>
        const items = document.querySelectorAll('[wm-dropzone] .item')
        items.forEach((itemindex=> {
            item.draggable = true
            item.id = item.id || `draggable-item-${index}`
            item.ondragstart = e =>
                e.dataTransfer.setData('item-id'e.target.id)
        })

        const dropzones = document.querySelectorAll('[wm-dropzone]')
        dropzones.forEach(dropzone => {
            dropzone.ondragover = e => e.preventDefault()
            dropzone.ondrop = function(e) {
                const id = e.dataTransfer.getData('item-id')
                const item = document.getElementById(id)
                //e.target.appendChild(item)
                dropzone.appendChild(item)
            }
        })
    </script>
</body>

</html>




Nenhum comentário: