NOTESSIDAN

Allt om Lotus Notes & Domino




Kod för att dra och släppa en div
Dra och släpp mig
Ett Dra och släpp exempel


Stylesheet


.box {
  background-color: #C0C0C0;
  border: 1px solid #000000;
  color: #000000;
  padding: 0px;
  position: relative;
}

.bar {
  background-color: #386089;
  color: #ffffff;
  cursor: move;
  font-weight: bold;
  padding: 2px 1em 2px 1em;
}
.content {
  padding: 1em;
}



HTML

<div id="boxB" class="box" style="width:200px">
  <div class="bar" 
       onmousedown="dragStart(event, 'boxB')">Dra och släpp mig</div>
  <div class="content" style="width:100%;">Dra och släpp exempel</div>
</div>



Javascript, Lägg i JS Header

function Browser() {

  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

var browser = new Browser();

// Global object to hold drag information.

var dragObj = new Object();
dragObj.zIndex = 0;

function dragStart(event, id) {

  var el;
  var x, y;

  // If an element id was given, find it. Otherwise use the element being
  // clicked on.

  if (id)
    dragObj.elNode = document.getElementById(id);
  else {
    if (browser.isIE)
      dragObj.elNode = window.event.srcElement;
    if (browser.isNS)
      dragObj.elNode = event.target;

    // If this is a text node, use its parent element.

    if (dragObj.elNode.nodeType == 3)
      dragObj.elNode = dragObj.elNode.parentNode;
  }

  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Save starting positions of cursor and element.

  dragObj.cursorStartX = x;
  dragObj.cursorStartY = y;
  dragObj.elStartLeft  = parseInt(dragObj.elNode.style.left, 10);
  dragObj.elStartTop   = parseInt(dragObj.elNode.style.top,  10);

  if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0;
  if (isNaN(dragObj.elStartTop))  dragObj.elStartTop  = 0;

  // Update element's z-index.

  dragObj.elNode.style.zIndex = ++dragObj.zIndex;

  // Capture mousemove and mouseup events on the page.

  if (browser.isIE) {
    document.attachEvent("onmousemove", dragGo);
    document.attachEvent("onmouseup",   dragStop);
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS) {
    document.addEventListener("mousemove", dragGo,   true);
    document.addEventListener("mouseup",   dragStop, true);
    event.preventDefault();
  }
}

function dragGo(event) {

  var x, y;

  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Move drag element by the same amount the cursor has moved.

  dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px";
  dragObj.elNode.style.top  = (dragObj.elStartTop  + y - dragObj.cursorStartY) + "px";

  if (browser.isIE) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS)
    event.preventDefault();
}

function dragStop(event) {

  // Stop capturing mousemove and mouseup events.

  if (browser.isIE) {
    document.detachEvent("onmousemove", dragGo);
    document.detachEvent("onmouseup",   dragStop);
  }
  if (browser.isNS) {
    document.removeEventListener("mousemove", dragGo,   true);
    document.removeEventListener("mouseup",   dragStop, true);
  }
}

Mer info finns här



Relevanta Poster på Notessidan:



Fler Poster om: Javascript, Lotus Notes, DIV, HTML, CSS

Fler bloggar om: , , , ,

Technorati: , , , ,

Delicious: Javascript, Lotus Notes, DIV, HTML, CSS
Publicerad 2007-11-28 | Kommentarer: 0 | Läsningar: 1977
Kommentarer

No documents found



Sök på Notessidan
Thomas Adrian
ThomasCertifierad utvecklare och administratör inom Notes & Domino

Kontakta mig







Senaste Sökningarna på Notessidan
Ons - svenska and mallar and notes and 8 (R:1)
Ons - importera and helgdagar (R:2)
Ons - kalender and i and notes (R:15)
Ons - schedule and mail (R:2)
Ons - system (R:43)
Ons - F�rlora and �,�,� (R:0)
Ons - s�kerhet (R:0)
Ons - busytime.ntf (R:2)
Ons - ändra and användare (R:23)
Ons - korrupt (R:3)
Ons - reload (R:4)
Ons - a (R:440)
Ons - update and site (R:15)
Ons - utf (R:21)
Ons - Notes and Svenska (R:33)
Ons - memory (R:4)
Ons - java and lotusscript (R:26)
Ons - outlines (R:4)
Ons - quickr (R:4)
Ons - lists (R:4)
Ons - auto.mdb (R:0)
Ons - Grafer (R:12)
Ons - 8.5.2 (R:6)
Ons - word (R:37)
Ons - bad and day (R:2)
Ons - Forum (R:24)
Ons - kurs* (R:8)
Ons - image (R:97)
Ons - notes and visar and mail (R:32)
Ons - group (R:12)




Databasstatistik Blogg
Uppdateras var 15:e Minut

Antal Poster:555
Antal Kommentarer: 984
Alla sidvisningar idag:
Unika Besökare idag:
Databasstorlek: 111,25Mb
Fixup: 2014-10-22 06:30:59
FT:2014-10-22 23:57:18
DB Procent använd: 98,1
Antal Agenter: 42
Antal Formulär: 65
Antal Vyer: 60
Antal Dokument: 9144
Antal Image Resources: 108
Antal Subformulär: 18
Antal Scriptbibliotek: 11
Totalt Antal Designelement: 552
Antal Attachments: 156
Antal Konflikter: 0
Server version 1: 405
Server version 2: Release 9.0.1|October 14, 2013
Server Plattform: Windows/64
Ändrad: 2014-10-23 00:27:55
Server Tidszon: Z=-1$DO=1$DL=3 -1 1 10 -1 1$ZX=97$ZN=W. Europe
Region:
Kommentarsspam Idag: 0
Kommentarsspam Totalt: 3368


BlogRankers.com

Top Sites at iWEBTOOL.com

Fight Spam! Click Here!

Bloggtoppen.se

Listed on BlogShares

Increase website traffic

Top Internet Blogs

Site Checker