Visualizzazione dei risultati da 1 a 2 su 2

Discussione: Drag and drop html5

  1. #1

    Drag and drop html5

    salve
    a tutti ho questo Script che serve per il Drag and drop con HTML5
    <script>
    trascinati = new Array();
    var x = 0;
    var entita = {

    cliente: {
    name: "CLIENTE",

    },
    agente: {
    name: "AGENTE",
    ...
    ...
    ...


    };

    function cancel(e) {
    if (e.preventDefault) {
    e.preventDefault();
    }
    return false;
    }
    var dragItems = document.querySelectorAll('[draggable=true]');

    for (var i = 0; i < dragItems.length; i++) {
    addEvent(dragItems[i], 'dragstart', function (event) {
    // store the ID of the element, and collect it on the drop later on
    event.dataTransfer.setData('Text', this.id);
    return false;
    });
    }

    var drop = document.querySelector('#drop');

    // Tells the browser that we *can* drop on this target
    addEvent(drop, 'dragover', cancel);
    addEvent(drop, 'dragenter', cancel);

    addEvent(drop, 'drop', function (event) {
    if (event.preventDefault)
    event.preventDefault(); // stops the browser from redirecting off to the text.

    var el = entita[event.dataTransfer.getData('Text')];


    trascinati.push(el.name);

    x = trascinati.length;
    alert(x.toString());

    if (x == 1) {
    this.innerHTML += '[img]icone/' + el.name + '.jpg[/img]';
    }
    else {
    //controllo che l'elemento trascinato non sia nella lista trascinato
    for (var j = 1; j <= x; j++) {

    if (trascinati[j] == "CLIENTE") {
    alert("hai gia trascinato questo elemento");
    }
    else {
    this.innerHTML += '[img]icone/' + el.name + '.jpg[/img]';
    }
    }
    }

    return false;
    });
    </script>

    Funziona la parte del trascinamento ma vorrei che gli elemnti gia trascinati ,quando vengono ritrascinati dell'area di drop mi diano un alert che non è possibile trascinarli.

  2. #2
    Preciso:
    voglio dire nel codice salta l'if e l'else

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.