Prova con questo, fa tutto quello che chiedi…Originariamente inviato da mest_suc
da dove le prendo le variabili delle coordinate da salvare nel cookie?
e poi come faccio a fargli scrivere che il div "votazione" è visualizzato o meno?
Ivano
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 oDragging, nMouseX, nMouseY, nStartX, nStartY, bMouseUp = true, nZFocus = 100 /* the highest z-Index present in your page plus 1 */, sDnDPref = "dr-drp_", oCookies = new (function(sCookies) { for (var iCouple, iIdx = 0, aCookies = sCookies.split(/;\s?/); iIdx < aCookies.length; iIdx++) { iCouple = aCookies[iIdx].split("="); this[unescape(iCouple[0])] = iCouple.length > 1 ? unescape(iCouple[1]) : ""; } })(document.cookie); function dragDown(oPssEvt1) { var oMsEvent1 = oPssEvt1 || /* IE */ window.event; for (var bExit = true, 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; if (oDragging.id) { document.cookie = escape(sDnDPref + oDragging.id) + "=" + escape(oDragging.style.left + "|" + oDragging.style.top + "|block|" + oDragging.style.zIndex) + "; path=/"; } } function dragShow(sToShowId) { var oToShow = document.getElementById(sToShowId) oToShow.style.display = "block"; document.cookie = escape(sDnDPref + sToShowId) + "=" + escape(oToShow.style.left + "|" + oToShow.style.top + "|block|" + oToShow.style.zIndex) + "; path=/"; } function dragHide(sToHideId) { var oToHide = document.getElementById(sToHideId); oToHide.style.display = "none"; document.cookie = escape(sDnDPref + sToHideId) + "=" + escape(oToHide.style.left + "|" + oToHide.style.top + "|none|" + oToHide.style.zIndex) + "; path=/"; } function dragReset() { var oToSet, aVals, nNewZ; for (var iCookie in oCookies) { if (iCookie.indexOf(sDnDPref) !== 0) { continue; } oToSet = document.getElementById(iCookie.slice(sDnDPref.length)); if (!oToSet) { continue; } aVals = oCookies[iCookie].split("|"); if (aVals.length > 0) { oToSet.style.left = aVals[0]; oToSet.style.top = aVals[1]; oToSet.style.display = aVals[2]; oToSet.style.zIndex = aVals[3]; nNewZ = parseFloat(aVals[3]); if (nNewZ >= nZFocus) { nZFocus = nNewZ + 1; } } } } document.onmousedown = dragDown; document.onmousemove = dragMove; document.onmouseup = dragUp; document.onkeypress = keyListener; window.onload = dragReset; function keyListener(oPssEvt3) { var oKeyEvt1 = oPssEvt3 || /* IE */ window.event; if (oKeyEvt1.ctrlKey && oKeyEvt1.charCode === 109) { /* ctrl + m */ dragShow("votazione"); } } </script> <style type="text/css"> .intLink { cursor: pointer; text-decoration: underline; color: #0000ff; } .draggable { position: fixed; left: 0; top: 0; width: auto; height: auto; cursor: move; } #votazione { width: 300px; height: 200px; left: 200px; top: 200px; background-color: #00ff00; display: none; } </style> </head> <body> Premi ctrl + m !!</p> <div class="draggable" id="votazione"> Votazione</p> <span class="intLink" onclick="dragHide('votazione');">Chiudi</span></p> </div> <div class="draggable" id="altroDiv" style="background-color:#aaaaaa;width:450px;height:200px;left:200px;top:200px;display:none;"> Un altro Div!!</p> <span class="intLink" onclick="dragHide('altroDiv');">Chiudi</span></p> </div> <span class="intLink" onclick="dragShow('altroDiv');">Apri altro div!!</span></p> </body> </html>


Rispondi quotando