[js/dhtml]

CPU

Lieutenant
Registriert
Jan. 2006
Beiträge
704
[js/dhtml] Drag & Drop

Hi Leude,

Um was muss ich den Code erweitern, damit eine Alert-Box kommt, wenn ich das A auf den div-Bereich ziehe? Dabei sollte die Alert-Box die Id des Elements (a) anzeigen.

Ich fänd's super wenn mir jemand helfen würd,
CPU :)

HTML:
<html>
 <head>
 <title>Drag&Drop</title>
<style>
 .drag {
  position:relative;
  cursor:move;
  z-index:0
 }
</style>
<script type="text/javascript">

 function move(){
 if (event.button==1&&dragapproved){
 z.style.pixelLeft=temp1+event.clientX-x
 z.style.pixelTop=temp2+event.clientY-y
 return false}
 }

 function drags(){
 if (!document.all)
 return
 if (event.srcElement.className=="drag"){
 dragapproved=true
 z=event.srcElement
 temp1=z.style.pixelLeft
 temp2=z.style.pixelTop
 x=event.clientX
 y=event.clientY
 document.onmousemove=move}
 }

 document.onmousedown=drags
 document.onmouseup=new Function("dragapproved=false")
</script>
</head>
<body>
 <div style="position:absolute; left: 200px; top: 200px"><h1 class="drag" id="a">A</h1></div>
 <div style="position:absolute; border: solid 1px; width: 100px; height: 100px; left: 20px; top: 20px"></div>
</body>
</html>
 
Zuletzt bearbeitet:

Ähnliche Themen

Antworten
4
Aufrufe
1.423
Smartass
S
Antworten
10
Aufrufe
1.787
Antworten
4
Aufrufe
1.093
H
Zurück
Oben