hellotk
Messages postés13Date d'inscriptionjeudi 15 février 2007StatutMembreDernière intervention 4 avril 2011
-
21 mars 2011 à 13:31
hellotk
Messages postés13Date d'inscriptionjeudi 15 février 2007StatutMembreDernière intervention 4 avril 2011
-
24 mars 2011 à 14:41
Bonjour à tous,
je rencontre un problème lié au drag&drop :
j'ai sur ma page plusieurs DIV (contenant des photos) dont la fonction drag&drop est appelée par javascript.
Jusque là tout va bien...
Or, lorsque je place un lien (href) sur l'image contenue dans une DIV,
la fonction drag&drop ne fonctionne plus.
Je cherche donc une solution qui me permette par exemple d'atteindre mon lien par double-click pour que la fonction drag&drop soit conservée.
hellotk
Messages postés13Date d'inscriptionjeudi 15 février 2007StatutMembreDernière intervention 4 avril 2011 23 mars 2011 à 14:08
re-bonjour,
J'ai un dernier petit soucis sur ma fonction drag&drop,
je n'arrives pas à faire en sorte que mes divs passent au premier plan lorsque je les sélectionnent,
je sais que ça a avoir avec le zIndex mais je ne sais pas comment l'assigner dans mon javascript :(
007Julien
Messages postés276Date d'inscriptionmercredi 22 septembre 2010StatutMembreDernière intervention 8 janvier 20144 23 mars 2011 à 21:30
Dans la fonction drag, appelée au début du déplacement, c'est lorsque l'on a « attrapé » le container de class drag qu'il convient de modifier le zIndex.
// D'où la modification
if (this.targetobj.className=="drag"){
this.dragapproved=1;// avec un point virgule cela serait mieux
this.targetobj.style.zIndex='999';// Ajout
// la suite avec des points virgules en fin de ligne afin que le code supporte des compressions
// les noms à rallonge type offsetx, offsety, targetobj, dragapproved pourraient également être quelque peu réduits...
// ...
}
// Mais il convient aussi de revenir à la valeur initiale
// en fin de déplacement d'où un autre ajout (un peu au dessus)
document.onmouseup=function(){this.dragapproved=0;
this.targetobj.style.zIndex='';}
Le 999 permet de passer au dessus de l'image de la ligthbox (de zIndex='90') lorsque le drag and drop est encore efficace en sa présence (c'est-à-dire avec IE).
hellotk
Messages postés13Date d'inscriptionjeudi 15 février 2007StatutMembreDernière intervention 4 avril 2011 24 mars 2011 à 09:30
entendu, on a don :
var dragobject={
x:0, y:0, offsetx:null,offsety:null,targetobj:null,dragapproved:0,
initialize:function(){
document.onmousedown=this.drag
document.onmouseup=function(){this.dragapproved=0; this.targetobj.style.zIndex='90';}}
,drag:function(e){
var evtobj=window.event? window.event:e
this.targetobj=window.event? event.srcElement:e.target
while (this.targetobj.className!="drag" && this.targetobj.tagName!="BODY") this.targetobj=this.targetobj.parentNode
if (this.targetobj.className=="drag"){
this.dragapproved=1;
this.targetobj.style.zIndex='999';
if (isNaN(parseInt(this.targetobj.style.left))){this.targetobj.style.left=0}
if (isNaN(parseInt(this.targetobj.style.top))){this.targetobj.style.top=0}
this.offsetx=parseInt(this.targetobj.style.left)
this.offsety=parseInt(this.targetobj.style.top)
this.x=evtobj.clientX
this.y=evtobj.clientY
if (evtobj.preventDefault) evtobj.preventDefault()
document.onmousemove=dragobject.moveit}}
mais pourrait-on forcer l'image à venir au premier plan lorsque l'on drope?
Car dans cet exemple, une foi relâchée , celle-ci se repositionne en arrière plan
hellotk
Messages postés13Date d'inscriptionjeudi 15 février 2007StatutMembreDernière intervention 4 avril 2011 24 mars 2011 à 14:41
J'ai trouvé ! j'ai ajouté une variable zindex que j'ai incrémentée à mon mouseup :
var z=1
var dragobject={
x:0, y:0, offsetx:null,offsety:null,targetobj:null,dragapproved:0,
initialize:function(){
document.onmousedown=this.drag
document.onmouseup=function(){this.dragapproved=0; this.targetobj.style.zIndex=z++;}}
,drag:function(e){
var evtobj=window.event? window.event:e
this.targetobj=window.event? event.srcElement:e.target
while (this.targetobj.className!="drag" && this.targetobj.tagName!="BODY") this.targetobj=this.targetobj.parentNode
if (this.targetobj.className=="drag"){
this.dragapproved=1;
this.targetobj.style.zIndex='999';
if (isNaN(parseInt(this.targetobj.style.left))){this.targetobj.style.left=0}
if (isNaN(parseInt(this.targetobj.style.top))){this.targetobj.style.top=0}
this.offsetx=parseInt(this.targetobj.style.left)
this.offsety=parseInt(this.targetobj.style.top)
this.x=evtobj.clientX
this.y=evtobj.clientY
if (evtobj.preventDefault) evtobj.preventDefault()
document.onmousemove=dragobject.moveit}}