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
Sön - öppnades (R:0)
Sön - excel and script (R:3)
Sön - design and 8 (R:12)
Sön - olästa (R:4)
Sön - svensk and version (R:8)
Sön - oläst (R:1)
Sön - stefan (R:2)
Sön - hoppa and mellan and flikar (R:1)
Sön - webapplikation (R:1)
Sön - lclsx (R:1)
Sön - stoppar and mail (R:1)
Sön - 2008 (R:7)
Sön - 454 (R:0)
Sön - getto (R:0)
Sön - imageresources (R:1)
Sön - slump (R:1)
Sön - öppnades (R:1)
Sön - ID (R:87)
Sön - extension (R:14)
Sön - wikipedia (R:15)
Sön - veckonummer and i and lotus and notes and 9 (R:0)
Sön - traveler (R:8)
Sön - skicka and länk (R:2)
Sön - connections (R:8)
Sön - notesmanager (R:5)
Sön - parameter (R:14)
Sön - web (R:97)
Sön - @hour (R:1)
Sön - replication and error (R:2)
Sön - Dojo and Charts and in and xPages and in and a and Composite and Application (R:1)




Databasstatistik Blogg
Uppdateras var 15:e Minut

Antal Poster:555
Antal Kommentarer: 984
Alla sidvisningar idag:
Unika Besökare idag:
Databasstorlek: 105,5Mb
Fixup: 2014-11-23 06:31:01
FT:2014-11-23 13:17:29
DB Procent använd: 99,3
Antal Agenter: 42
Antal Formulär: 65
Antal Vyer: 60
Antal Dokument: 9211
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.1FP2|August 03, 2014
Server Plattform: Windows/64
Ändrad: 2014-11-23 13:26:10
Server Tidszon: Z=-1$DO=1$DL=3 -1 1 10 -1 1$ZX=97$ZN=W. Europe
Region:
Kommentarsspam Idag: 0
Kommentarsspam Totalt: 3425


BlogRankers.com

Top Sites at iWEBTOOL.com

Fight Spam! Click Here!

Bloggtoppen.se

Listed on BlogShares

Increase website traffic

Top Internet Blogs

Site Checker