Visualizzazione dei risultati da 1 a 3 su 3

Discussione: bind in for

  1. #1
    Utente di HTML.it
    Registrato dal
    Aug 2007
    Messaggi
    13

    bind in for

    maledetto jquery....

    ho provato ad aggiungere in un ciclo for delle funzioni bind di un oggetto draggabile ma non ne vuole sapere di funzionare...

    come posso fare?

    altre info:

    in poche parole il ciclo for dovrebbe creare n funzioni bind legate ad n oggetti draggabili già creati e funzionanti

    come controprova ho fatto un bind su un oggetto specifico di questi e funziona

  2. #2
    Utente di HTML.it L'avatar di carlomarx
    Registrato dal
    Oct 2009
    Messaggi
    1,669
    Invece di creare infinite funzioni con bind (in generale non è mai una buona idea abusare di bind) creane una sola e falle sfruttare i diversi id degli elementi in questione. Altrimenti un'altra possibilità è usare l'attributo class, come in questo esempio:

    codice:
    <!doctype html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Draggable objects</title>
    <script type="text/javascript">
    
    var bMouseUp = true, oDragging, nMouseX, nMouseY, nStartX, nStartY, nZFocus = 100 /* the highest z-Index present in your page plus 1 */;
    
    function dragDown(oPssEvt1) {
      var bExit = true, oMsEvent1 = oPssEvt1 || /* IE */ window.event;
      for (var iNode = oMsEvent1.target; iNode; iNode = iNode.parentNode) {
        if (iNode.className === "draggable") { bExit = false; oDragging = iNode; break; }
      }
      if (bExit) { return; }
      bMouseUp = false;
      nStartX = nStartY = 0;
      for (var iOffPar = oDragging; iOffPar; iOffPar = iOffPar.offsetParent) {
        nStartX += iOffPar.offsetLeft;
        nStartY += iOffPar.offsetTop;
      }
      nMouseX = oMsEvent1.clientX;
      nMouseY = oMsEvent1.clientY;
      oDragging.style.zIndex = nZFocus++;
      return false;
    }
    
    function dragMove(oPssEvt2) {
      if (bMouseUp) { return; }
      var oMsEvent2 = oPssEvt2 || /* IE */ window.event;
      oDragging.style.left = String(nStartX + oMsEvent2.clientX - nMouseX) + "px";
      oDragging.style.top = String(nStartY + oMsEvent2.clientY - nMouseY) + "px";
    }
    
    function dragUp() { bMouseUp = true; }
    
    document.onmousedown = dragDown;
    document.onmousemove = dragMove;
    document.onmouseup = dragUp;
    
    </script>
    <style type="text/css">
    .draggable {
      position: fixed;
      left: 0;
      top: 0;
      width: auto;
      height: auto;
      cursor: move;
    }
    
    #myDiv {
      width: 300px;
      height: 200px;
      left: 200px;
      top: 200px;
      background-color: #00ff00;
    }
    </style>
    </head>
    
    <body>
    
    <div class="draggable" id="myDiv">
    
    Hello world!</p></div>
    <div class="draggable" style="background-color:#aaaaaa;">Another hello world!</div>
    
    </body>
    </html>
    https://developer.mozilla.org/en/DOM...nt.onmousemove

  3. #3
    Utente di HTML.it
    Registrato dal
    Aug 2007
    Messaggi
    13
    ho messo la bind come una classe e ora funge tutto a meraviglia
    grazieeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee

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.