Plasser byene i riktig land
Sevilla
Milano
Parma
Valencia
Barcelona
Venezia
Napoli
Bari
Bilbao
|
Stilsettet
_style1.css
/* Prevent the text contents of draggable elements from being selectable. */ [draggable] { -moz-user-select: none; -khtml-user-select: none; -webkit-user-select: none; user-select: none; } .city:hover{border: 1px dashed #000;cursor:pointer} #cities{min-height:50px;margin-top:20px} #cities div{text-align:center;display:inline-block; margin:0px 3px 0px 3px;padding:0px 0px 0px 0px} table td{vertical-align:top; width:100px} table td:nth-child(2){width:200px} .country{min-height:100px} .country legend{font-size:18px;color:blue;font-weight:bold}
Javascript
_script1.js
var draggedElt = null; var cities=null; var countries=null; function handleDragStart(e) { draggedElt = this; e.dataTransfer.effectAllowed = 'move'; e.dataTransfer.setData('text/html', this.innerHTML); } function handleDragOver(e) { if (e.preventDefault) { e.preventDefault(); // Allows drop. } if(draggedElt==this) { e.dataTransfer.dropEffect = 'move'; } return false; } function handleDrop(e) { if (e.stopPropagation) { e.stopPropagation(); } if (draggedElt != this) { if(this.classList.contains('city')) this.parentNode.appendChild(draggedElt); else this.appendChild(draggedElt); draggedElt=null; } if(document.getElementById('cities').getElementsByTagName('div').length==0) document.getElementById('message').innerHTML='ingen kontroll, men du kan jo sjekke kartet før du drar på ferie'; else document.getElementById('message').innerHTML=''; return false; } function init(){ cities = document.querySelectorAll('#cities div'); [].forEach.call(cities, function(city) { city.addEventListener('dragstart', handleDragStart, false); city.addEventListener('dragover', handleDragOver, false); city.addEventListener('drop', handleDrop, false); }); countries=document.querySelectorAll('.country'); [].forEach.call(countries, function(country) { country.addEventListener('dragover', handleDragOver, false); country.addEventListener('drop', handleDrop, false); }); }