IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JavaScript Discussion :

Drag and drop image en enregistrant la position image


Sujet :

JavaScript

  1. #1
    Débutant
    Inscrit en
    Juin 2006
    Messages
    502
    Détails du profil
    Informations forums :
    Inscription : Juin 2006
    Messages : 502
    Points : 78
    Points
    78
    Par défaut Drag and drop image en enregistrant la position image
    Bonjour à tous,

    Après quelques recherche et n'ayant rien trouvé je fais donc appel à vos connaissances.
    J'ai réaliser un site internet en PHP et je souhaite ajouter un drag and drop pour une galerie d'image. Je souhaite faire la même chose que dans facebook : Pouvoir déplacer mes images tout en enregistrant la position de l'image.
    Pouvez-vous m'aider svp.

    Merci d'avance.

  2. #2
    Membre à l'essai
    Profil pro
    Inscrit en
    Juillet 2010
    Messages
    15
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2010
    Messages : 15
    Points : 12
    Points
    12
    Par défaut
    Salut,

    Tu peux regarder ici si tu veux : http://www.defusion.org.uk/demos/060519/cropper.php

  3. #3
    Débutant
    Inscrit en
    Juin 2006
    Messages
    502
    Détails du profil
    Informations forums :
    Inscription : Juin 2006
    Messages : 502
    Points : 78
    Points
    78
    Par défaut
    Merci pour ta réponse mais ce n'est pas ça que je recherche.
    J'ai une galerie photo et je souhaiterai déplacer mes photos exemple l'image 1 de ma galerie je souhaiterai la mettre en 3eme position, la 4eme photo je souhaiterai la mettre en dernière etc...

  4. #4
    Membre à l'essai
    Profil pro
    Inscrit en
    Juillet 2010
    Messages
    15
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2010
    Messages : 15
    Points : 12
    Points
    12
    Par défaut
    Ah d'accord !

    Je connais la librairie Prototype donc je te donne des exemples qu'avec celle-ci

    Tu peux utiliser Sortable : http://wiki.github.com/madrobby/scriptaculous/sortable

    Et ensuite stocker leurs positions dans un cookies JS, mais si tu as beaucoup d'images, tu vas te retrouver avec une fichier cookie long ...

    Pourquoi ne pas faire le traitement directement sur la galerie ? C'est du php ?

  5. #5
    Débutant
    Inscrit en
    Juin 2006
    Messages
    502
    Détails du profil
    Informations forums :
    Inscription : Juin 2006
    Messages : 502
    Points : 78
    Points
    78
    Par défaut
    Merci pour ta réponse.

    Oui oui c'est PHP. J'avais pensé enregistrer en bdd la position de l'image (parceque des images il y en aura surement bcp). Mais je ne sais pas du tout comment m'y prendre.

  6. #6
    Membre à l'essai
    Profil pro
    Inscrit en
    Juillet 2010
    Messages
    15
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2010
    Messages : 15
    Points : 12
    Points
    12
    Par défaut
    Tu rajoute un champ dans ta table, tu enregistre ça position et ensuite dans ta requête tu fait un ORDER BY

  7. #7
    Débutant
    Inscrit en
    Juin 2006
    Messages
    502
    Détails du profil
    Informations forums :
    Inscription : Juin 2006
    Messages : 502
    Points : 78
    Points
    78
    Par défaut
    Oui oui merci je pensais faire ça. Mais je ne vois pas comment faire pour récupérer le numéro de position des image lors du déplacement. Je veux faire le même système que facebook pour l'organisation des images mais je ne c pas comment m'y prendre aprés pour l'enregistrement en bdd avec PHP je c faire mais le drag and drop et la récupération des positions que j'arrive pas

  8. #8
    Membre expérimenté
    Avatar de gwyohm
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Octobre 2007
    Messages
    925
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Octobre 2007
    Messages : 925
    Points : 1 333
    Points
    1 333
    Par défaut
    Bonjour,

    Si tu décides d'utiliser Sortable de script.aculo.us, tu auras quelque chose comme :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
    <div id="gallerie">
    <img src="..." id="image_1"/>
    <img src="..." id="image_2"/>
    <img src="..." id="image_2"/>
    </div>
    <input type="button" id="saveBtn" value="save"/>
    <script type="text/javascript">
    Sortable.create('gallerie');
    $("saveBtn").observe("click", function() {
      alert(Sortable.sequence('gallerie').join(","));
    });
    </script>
    donc tu changes le alert par du code qui envoie à ton php...
    on ne dit pas "ça ne marche pas" on dit "je suis incapable de faire fonctionner correctement les outils mis à ma disposition"
    Pas de question technique par MP

  9. #9
    Débutant
    Inscrit en
    Juin 2006
    Messages
    502
    Détails du profil
    Informations forums :
    Inscription : Juin 2006
    Messages : 502
    Points : 78
    Points
    78
    Par défaut
    Ok merci pour ce cou de pouce je vais tester ça

  10. #10
    Débutant
    Inscrit en
    Juin 2006
    Messages
    502
    Détails du profil
    Informations forums :
    Inscription : Juin 2006
    Messages : 502
    Points : 78
    Points
    78
    Par défaut
    J'ai réussi à faire un drag and drop d'image en récupérant un code sur internet le problème c'est que je ne sais pas comment faire pour enregistrer en base de donnée.

    Voici le code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
     
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    	<title>Dragable content</title>
    	<meta name="Author" content="Alf Magne Kalleland (post@dhtmlgoodies.com)">
    <META NAME="Generator" CONTENT="Alf Magne Kalleland (www.dhtmlgoodies.com)">
    <meta name="KeyWords" content="Drag and drop script, Drag and drop,Drag'n drop,Arrange content,Arrange nodes">
    <meta name="Description" content="A library of DHTML and Ajax scripts">
    <meta name="country" content="Norway">
    <meta name="organization-Email" content="post@dhtmlgoodies.com">
    <meta name="copyright" content="copyright 2005 - Alf Magne Kalleland">
    <meta name="coverage" content="Worldwide">
    <meta name="revisit_after" content="30days">
    <meta name="title" content="A library DHTML and Ajax scripts - DHTMLgoodies.com">
     
    <meta name="identifier" content="http://www.dhtmlgoodies.com/">
    <meta name="language" content="English">
    <meta name="robots" content="follow">
    <meta name="googlebot" content="index, follow">
     
    <script type="text/javascript">
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
    </script>
    <script type="text/javascript">
    var pageTracker = _gat._getTracker("UA-2042963-1");
    pageTracker._trackPageview();
    </script>
     
    	<style type="text/css">
    	/* CSS NEEDED ONLY IN THE DEMO */
    	html{
    		width:100%;
    		overflow-x:hidden;
    	}
    	body{
    		font-family: Trebuchet MS, Lucida Sans Unicode, Arial, sans-serif;
    		width:100%;
    		margin:0px;
    		padding:0px;
    		text-align:center;
    		background-color:#E2EBED;	
    		font-size:0.7em;	
    		overflow-x:hidden;
    	}
     
    	#mainContainer{
    		width:600px;
    		margin:0 auto;
    		text-align:left;
    		background-color:#FFF;
    	}
    	h4{
    		margin:0px;
    	}
    	p{
    		margin-top:5px;
    	}
     
     
     
    	/* This is the box that is parent to the dragable items */
    	#dragableElementsParentBox{
    		padding:10px;	/* Air */
    	}
     
    	.smallArticle,.bigArticle{
    		float:left;
    		border:1px solid #000;
    		background-color:#DDD;
    		padding:2px;
    		margin-right:10px;
    		margin-bottom:5px;
    	}
    	.smallArticle img,.bigArticle img{
    		float:left;
    		padding:5px;
    	}
    	.smallArticle .rightImage,.bigArticle .rightImage{
    		float:right;
    	}
    	.smallArticle{
    		/*width:274px;*/		
    	}
    	.bigArticle{
    		/*width:564px;*/
    	}
    	.clear{
    		clear:both;
    	}
     
    	/* END DEMO CSS */
     
    	/* REQUIRED CSS */
     
    	#rectangle{
    		float:left;
    		border:1px dotted #F00;	/* Red border */
    		background-color:#FFF;
    	}
    	#insertionMarker{	/* Don't change the rules for the insertionMarker */
    		width:6px;
    		position:absolute;
    		display:none;
    	}
    	#insertionMarker img{	/* Don't change the rules for the insertionMarker */
    		float:left;
    	}		
    	#dragDropMoveLayer{	/* Dragable layer - Not need if you're using 'rectangle' mode */
    		position:absolute;
    		display:none;
    		border:1px solid #000;
    		filter:alpha(opacity=50);	/* 50% opacity , i.e. transparency */
    		opacity:0.5;	/* 50% opacity , i.e. transparency */
     
    	}
     
    	/* END REQUIRED CSS */
    	</style>
     
    	<script type="text/javascript">
    	/************************************************************************************************************
    	(C) www.dhtmlgoodies.com, January 2006
     
    	This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.	
     
    	Terms of use:
    	You are free to use this script as long as the copyright message is kept intact. However, you may not
    	redistribute, sell or repost it without our permission.
     
    	Thank you!
     
    	www.dhtmlgoodies.com
    	Alf Magne Kalleland
     
    	************************************************************************************************************/	
     
     
    	var rectangleBorderWidth = 2;	// Used to set correct size of the rectangle with red dashed border
    	var useRectangle = true;
     
    	var autoScrollSpeed = 4;	// Autoscroll speed	- Higher = faster
     
    	/* Don't change anything below here */
     
     
    	var dragableElementsParentBox;
    	var opera = navigator.appVersion.indexOf('Opera')>=0?true:false;
     
    	var rectangleDiv = false;
    	var insertionMarkerDiv = false;
    	var mouse_x;
    	var mouse_y;
     
    	var el_x;
    	var el_y;
     
    	var dragDropTimer = -1;	// -1 = no drag, 0-9 = initialization in progress, 10 = dragging
    	var dragObject = false;
    	var dragObjectNextObj = false;
    	var dragableObjectArray = new Array();
    	var destinationObj = false;	
    	var currentDest = false;
    	var allowRectangleMove = true;
    	var insertionMarkerLine;
    	var dragDropMoveLayer;
    	var autoScrollActive = false;
    	var documentHeight = false;
    	var documentScrollHeight = false;
    	var dragableAreaWidth = false;
     
    	function getTopPos(inputObj)
    	{		
    	  var returnValue = inputObj.offsetTop;
    	  while((inputObj = inputObj.offsetParent) != null){
    	  	if(inputObj.tagName!='HTML')returnValue += inputObj.offsetTop;
    	  }
    	  return returnValue;
    	}
     
    	function getLeftPos(inputObj)
    	{
    	  var returnValue = inputObj.offsetLeft;
    	  while((inputObj = inputObj.offsetParent) != null){
    	  	if(inputObj.tagName!='HTML')returnValue += inputObj.offsetLeft;
    	  }
    	  return returnValue;
    	}
     
    	function cancelSelectionEvent()
    	{
    		if(dragDropTimer>=0)return false;
    		return true;
    	}
     
    	function getObjectFromPosition(x,y)
    	{
    		var height = dragObject.offsetHeight;
    		var width = dragObject.offsetWidth;
    		var indexCurrentDragObject=-5;
    		for(var no=0;no<dragableObjectArray.length;no++){			
    			ref = dragableObjectArray[no];			
    			if(ref['obj']==dragObject)indexCurrentDragObject=no;
    			if(no<dragableObjectArray.length-1 && dragableObjectArray[no+1]['obj']==dragObject)indexCurrentDragObject=no+1;
    			if(ref['obj']==dragObject && useRectangle)continue;	
    			if(x > ref['left'] && y>ref['top'] && x<(ref['left'] + (ref['width']/2)) && y<(ref['top'] + ref['height'])){
    				if(!useRectangle && dragableObjectArray[no]['obj']==dragObject)return 'self';
    				if(indexCurrentDragObject==(no-1))return 'self';
    				return Array(dragableObjectArray[no],no);
    			}
     
    			if(x > (ref['left'] + (ref['width']/2)) && y>ref['top'] && x<(ref['left'] + ref['width']) && y<(ref['top'] + ref['height'])){
    				if(no<dragableObjectArray.length-1){
    					if(no==indexCurrentDragObject || (no==indexCurrentDragObject-1)){
    						return 'self';
    					}
    					if(dragableObjectArray[no]['obj']!=dragObject){
    						return Array(dragableObjectArray[no+1],no+1);
    					}else{
    						if(!useRectangle)return 'self';
    						if(no<dragableObjectArray.length-2)return Array(dragableObjectArray[no+2],no+2);
    					}
    				}else{
    					if(dragableObjectArray[dragableObjectArray.length-1]['obj']!=dragObject)return 'append';	
     
    				}
    			}
    			if(no<dragableObjectArray.length-1){
    				if(x > (ref['left'] + ref['width']) && y>ref['top'] && y<(ref['top'] + ref['height']) && y<dragableObjectArray[no+1]['top']){
    					return Array(dragableObjectArray[no+1],no+1);
    				}
    			}
    		}	
    		if(x>ref['left'] && y>(ref['top'] + ref['height']))return 'append';				
    		return false;	
    	}
     
    	function initDrag(e)
    	{
    		if(document.all)e = event;
    		mouse_x = e.clientX;
    		mouse_y = e.clientY;
    		if(!documentScrollHeight)documentScrollHeight = document.documentElement.scrollHeight + 100;
    		el_x = getLeftPos(this)/1;
    		el_y = getTopPos(this)/1;
    		dragObject = this;
    		if(useRectangle){
    			rectangleDiv.style.width = this.clientWidth - (rectangleBorderWidth*2) +'px';
    			rectangleDiv.style.height = this.clientHeight - (rectangleBorderWidth*2) +'px';
    			rectangleDiv.className = this.className;
    		}else{
    			insertionMarkerLine.style.width = '6px';
    		}
    		dragDropTimer = 0;
    		dragObjectNextObj = false;
    		if(this.nextSibling){
    			dragObjectNextObj = this.nextSibling;
    			if(!dragObjectNextObj.tagName)dragObjectNextObj = dragObjectNextObj.nextSibling;
    		}
    		initDragTimer();
    		return false;
    	}
     
    	function initDragTimer()
    	{
    		if(dragDropTimer>=0 && dragDropTimer<10){
    			dragDropTimer++;
    			setTimeout('initDragTimer()',5);
    			return;
    		}
    		if(dragDropTimer==10){
     
    			if(useRectangle){
    				dragObject.style.opacity = 0.5;
    				dragObject.style.filter = 'alpha(opacity=50)';
    				dragObject.style.cursor = 'default';
    			}else{
    				var newObject = dragObject.cloneNode(true);
    				dragDropMoveLayer.appendChild(newObject);
    			}
    		}
    	}
     
     
    	function autoScroll(direction,yPos)
    	{
    		if(document.documentElement.scrollHeight>documentScrollHeight && direction>0)return;
     
    		window.scrollBy(0,direction);
     
    		if(direction<0){
    			if(document.documentElement.scrollTop>0){
    				mouse_y = mouse_y - direction;
    				if(useRectangle){
    					dragObject.style.top = (el_y - mouse_y + yPos) + 'px';
    				}else{
    					dragDropMoveLayer.style.top = (el_y - mouse_y + yPos) + 'px';
    				}			
    			}else{
    				autoScrollActive = false;
    			}
    		}else{
    			if(yPos>(documentHeight-50)){		
     
    				mouse_y = mouse_y - direction;
    				if(useRectangle){
    					dragObject.style.top = (el_y - mouse_y + yPos) + 'px';
    				}else{
    					dragDropMoveLayer.style.top = (el_y - mouse_y + yPos) + 'px';
    				}				
    			}else{
    				autoScrollActive = false;
    			}
    		}
    		if(autoScrollActive)setTimeout('autoScroll('+direction+',' + yPos + ')',5);
    	}
     
    	function moveDragableElement(e)
    	{
    		if(document.all)e = event;
     
    		if(dragDropTimer<10)return;
    		if(!allowRectangleMove)return false;
     
     
    		if(e.clientY<50 || e.clientY>(documentHeight-50)){
    			if(e.clientY<50 && !autoScrollActive){
    				autoScrollActive = true;
    				autoScroll((autoScrollSpeed*-1),e.clientY);
    			}
     
    			if(e.clientY>(documentHeight-50) && document.documentElement.scrollHeight<=documentScrollHeight && !autoScrollActive){
    				autoScrollActive = true;
    				autoScroll(autoScrollSpeed,e.clientY);
    			}
    		}else{
    			autoScrollActive = false;
    		}
    		if(useRectangle){			
    			if(dragObject.style.position!='absolute'){
    				dragObject.style.position = 'absolute';
    				setTimeout('repositionDragObjectArray()',50);
    			}
    		}		
     
    		if(useRectangle){
    			rectangleDiv.style.display='block';
    		}else{
    			insertionMarkerDiv.style.display='block';	
    			dragDropMoveLayer.style.display='block';	
    		}
     
    		if(useRectangle){
    			dragObject.style.left = (el_x - mouse_x + e.clientX + Math.max(document.body.scrollLeft,document.documentElement.scrollLeft)) + 'px';
    			dragObject.style.top = (el_y - mouse_y + e.clientY) + 'px';
    		}else{
    			dragDropMoveLayer.style.left = (el_x - mouse_x + e.clientX + Math.max(document.body.scrollLeft,document.documentElement.scrollLeft)) + 'px';
    			dragDropMoveLayer.style.top = (el_y - mouse_y + e.clientY) + 'px';
    		}
    		dest = getObjectFromPosition(e.clientX+Math.max(document.body.scrollLeft,document.documentElement.scrollLeft),e.clientY+Math.max(document.body.scrollTop,document.documentElement.scrollTop));
     
    		if(dest!==false && dest!='append' && dest!='self'){
    			destinationObj = dest[0]; 
     
    			if(currentDest!==destinationObj){
    				currentDest = destinationObj;
    				if(useRectangle){
    					destinationObj['obj'].parentNode.insertBefore(rectangleDiv,destinationObj['obj']);
    					repositionDragObjectArray();
    				}else{
    					if(dest[1]>0 && (dragableObjectArray[dest[1]-1]['obj'].offsetLeft + dragableObjectArray[dest[1]-1]['width'] + dragObject.offsetWidth) < dragableAreaWidth){
    						insertionMarkerDiv.style.left = (getLeftPos(dragableObjectArray[dest[1]-1]['obj']) + dragableObjectArray[dest[1]-1]['width'] + 2) + 'px';
    						insertionMarkerDiv.style.top = (getTopPos(dragableObjectArray[dest[1]-1]['obj']) - 2) + 'px';
    						insertionMarkerLine.style.height = dragableObjectArray[dest[1]-1]['height'] + 'px';
    					}else{					
    						insertionMarkerDiv.style.left = (getLeftPos(destinationObj['obj']) - 8) + 'px';
    						insertionMarkerDiv.style.top = (getTopPos(destinationObj['obj']) - 2) + 'px';
    						insertionMarkerLine.style.height = destinationObj['height'] + 'px';
    					}
     
     
    				}
    			}
    		}
     
    		if(dest=='self' || !dest){
    			insertionMarkerDiv.style.display='none';
    			destinationObj = dest;	
    		}
     
    		if(dest=='append'){
    			if(useRectangle){
    				dragableElementsParentBox.appendChild(rectangleDiv);
    				dragableElementsParentBox.appendChild(document.getElementById('clear'));
    			}else{
    				var tmpRef = dragableObjectArray[dragableObjectArray.length-1];
    				insertionMarkerDiv.style.left = (getLeftPos(tmpRef['obj']) + 2) + tmpRef['width'] + 'px';
    				insertionMarkerDiv.style.top = (getTopPos(tmpRef['obj']) - 2) + 'px';
    				insertionMarkerLine.style.height = tmpRef['height'] + 'px';	
    			}
    			destinationObj = dest;
    			repositionDragObjectArray();
    		}	
     
    		if(useRectangle && !dest){
    			destinationObj = currentDest;
    		}
     
    		allowRectangleMove = false;
    		setTimeout('allowRectangleMove=true',50);
    	}
     
    	function stop_dragDropElement()
    	{
    		dragDropTimer = -1;
     
    		if(destinationObj && destinationObj!='append' && destinationObj!='self'){
    			destinationObj['obj'].parentNode.insertBefore(dragObject,destinationObj['obj']);
    		}
    		if(destinationObj=='append'){
    			dragableElementsParentBox.appendChild(dragObject);
    			dragableElementsParentBox.appendChild(document.getElementById('clear'));
    		}
     
    		if(dragObject && useRectangle){
    			dragObject.style.opacity = 1;
    			dragObject.style.filter = 'alpha(opacity=100)';
    			dragObject.style.cursor = 'move';
    			dragObject.style.position='static';
    		}
    		rectangleDiv.style.display='none';
    		insertionMarkerDiv.style.display='none';
    		dragObject = false;
    		currentDest = false;
    		resetObjectArray();
    		destinationObj = false;
    		if(dragDropMoveLayer){
    			dragDropMoveLayer.style.display='none';
    			dragDropMoveLayer.innerHTML='';
    		}
    		autoScrollActive = false;
    		documentScrollHeight = document.documentElement.scrollHeight + 100;
    	}
     
    	function cancelEvent()
    	{
    		return false;
    	}
     
    	function repositionDragObjectArray()
    	{
    		for(var no=0;no<dragableObjectArray.length;no++){
    			ref = dragableObjectArray[no];
    			ref['left'] = getLeftPos(ref['obj']);
    			ref['top'] = getTopPos(ref['obj']);			
    		}	
    		documentScrollHeight = document.documentElement.scrollHeight + 100;
    		documentHeight = document.documentElement.clientHeight;
    	}
     
    	function resetObjectArray()
    	{
    		dragableObjectArray.length=0;
    		var subDivs = dragableElementsParentBox.getElementsByTagName('*');
    		var countEl = 0;
     
    		for(var no=0;no<subDivs.length;no++){
    			var attr = subDivs[no].getAttribute('dragableBox');
    			if(opera)attr = subDivs[no].dragableBox;
    			if(attr=='true'){
    				var index = dragableObjectArray.length;
    				dragableObjectArray[index] = new Array();
    				ref = dragableObjectArray[index];
    				ref['obj'] = subDivs[no];
    				ref['width'] = subDivs[no].offsetWidth;
    				ref['height'] = subDivs[no].offsetHeight;
    				ref['left'] = getLeftPos(subDivs[no]);
    				ref['top'] = getTopPos(subDivs[no]);
    				ref['index'] = countEl;
    				countEl++;
    			}
    		}	
    	}
     
    	/* The saveData function creates a string containing the ids of your dragable elements. 
     
    	The format of this string is as follow
     
    	id of item 1;id of item 2;id of item 3
     
    	i.e. a semi colon separated list. The id is something you put in as "id" attribute of your dragable elements.
     
    	*/
     
    	function saveData()
    	{
    		var saveString = "";
    		for(var no=0;no<dragableObjectArray.length;no++){
    			if(saveString.length>0)saveString = saveString + ';';
    			ref = dragableObjectArray[no];
    			saveString = saveString + ref['obj'].id;
    		}	
     
    		alert(saveString);	// For demo only
     
    		/* 	Put this item into a hidden form field and then submit the form 
     
    		example:*/
     
    		//document.forms[0].itemOrder.value = saveString;
    		//document.forms[0].submit;
     
    		/*On the server explode the values by use of server side script. Then update your database with the new item order
     
    		*/
     
     
     
    	}
     
    	function initdragableElements()
    	{
    		dragableElementsParentBox = document.getElementById('dragableElementsParentBox');
    		insertionMarkerDiv = document.getElementById('insertionMarker');
    		insertionMarkerLine = document.getElementById('insertionMarkerLine');
    		dragableAreaWidth = dragableElementsParentBox.offsetWidth;
     
    		if(!useRectangle){
    			dragDropMoveLayer = document.createElement('DIV');
    			dragDropMoveLayer.id = 'dragDropMoveLayer';		
    			document.body.appendChild(dragDropMoveLayer);	
    		}
     
    		var subDivs = dragableElementsParentBox.getElementsByTagName('*');
    		var countEl = 0;
    		for(var no=0;no<subDivs.length;no++){
    			var attr = subDivs[no].getAttribute('dragableBox');
    			if(opera)attr = subDivs[no].dragableBox;
    			if(attr=='true'){
    				subDivs[no].style.cursor='move';	
    				subDivs[no].onmousedown = initDrag;
     
    				var index = dragableObjectArray.length;
    				dragableObjectArray[index] = new Array();
    				ref = dragableObjectArray[index];
    				ref['obj'] = subDivs[no];
    				ref['width'] = subDivs[no].offsetWidth;
    				ref['height'] = subDivs[no].offsetHeight;
    				ref['left'] = getLeftPos(subDivs[no]);
    				ref['top'] = getTopPos(subDivs[no]);
    				ref['index'] = countEl;
    				countEl++;
    			}
    		}
     
    		/* Creating rectangel indicating where item will be dropped */
    		rectangleDiv = document.createElement('DIV');
    		rectangleDiv.id='rectangle';
    		rectangleDiv.style.display='none';
    		dragableElementsParentBox.appendChild(rectangleDiv);
     
     
    		document.body.onmousemove = moveDragableElement;
    		document.body.onmouseup = stop_dragDropElement;
    		document.body.onselectstart = cancelSelectionEvent;
    		document.body.ondragstart = cancelEvent;
    		window.onresize = repositionDragObjectArray; 
     
    		documentHeight = document.documentElement.clientHeight;
    	}
     
    	window.onload = initdragableElements;
     
    	</script>
    </head>
    <body>
     
    <div id="mainContainer">
      <div id="header">
    	<img src="/images/heading3.gif">
      </div>
     
     
    	<!-- START DRAGABLE CONTENT -->
    <form id="forms">
    	<div id="dragableElementsParentBox">
    		<div class="bigArticle" dragableBox="true" id="article1">
            <input type="hidden" value="article1">
    			<img src="images/img.jpg" >
    		</div>
    		<div class="smallArticle" dragableBox="true" id="article2">
            <input type="hidden" value="article2">
    			<img src="images/img2.jpg">
    				</div>
    		<div class="smallArticle" dragableBox="true" id="article3">
            <input type="hidden" value="article3">
    			<img src="images/img3.jpg">
     
     
    		</div>
    		<div class="clear" id="clear"></div>
     
    	</div>
     
    	<!-- END DRAGABLE CONTENT -->
     
    <input type="button" value="Save" onclick="saveData()">
        </form>	
    </div>
    <!-- REQUIRED DIVS -->
    <div id="insertionMarker">
    	<img src="images/marker_top.gif">
     
    	<img src="images/marker_middle.gif" id="insertionMarkerLine">
    	<img src="images/marker_bottom.gif">
    </div>
    <!-- END REQUIRED DIVS -->
    <script type="text/javascript">
        var infolink_pid = 8714;
    	 var infolink_wsid = 0; 	
        var infolink_link_color = '009900';
        var infolink_title_color = '252667';
        var infolink_text_color = '000000';
        var infolink_ad_link_color = '24951E';
        var infolink_ad_effect_type = 0;
        var infolink_cat = 'software development';
    </script>
    <script type="text/javascript" src="http://resources.infolinks.com/js/infolinks_main.js"></script>
    	</body>
    </html>
    Si vous pouvez m'aider.

    Merci d'avance.

  11. #11
    Rédacteur

    Avatar de Bovino
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juin 2008
    Messages
    23 647
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2008
    Messages : 23 647
    Points : 91 220
    Points
    91 220
    Billets dans le blog
    20
    Par défaut
    Dis-moi, tu demandes de l'aide ou juste qu'on fasse le code à ta place ?

    Tu as essayé de faire quelque chose au moins ?

    Il y a beaucoup de personnes qui donnent de leur temps pour aider, abuser de leur gentillesse en crachant plus de 600 lignes de code en disant juste : voilà ce que j'ai pompé ailleurs, merci de me faire le reste me semble particulièrement irrespectueux !
    Pas de question technique par MP !
    Tout le monde peut participer à developpez.com, vous avez une idée, contactez-moi !
    Mes formations video2brain : La formation complète sur JavaScriptJavaScript et le DOM par la pratiquePHP 5 et MySQL : les fondamentaux
    Mon livre sur jQuery
    Module Firefox / Chrome d'intégration de JSFiddle et CodePen sur le forum

  12. #12
    Débutant
    Inscrit en
    Juin 2006
    Messages
    502
    Détails du profil
    Informations forums :
    Inscription : Juin 2006
    Messages : 502
    Points : 78
    Points
    78
    Par défaut
    Je te rassure je veux juste de l'aide et non qu'on fasse le code à ma place.
    J'ai cherche des pistes sur internet j'ai tenté des choses et sans succès et c'est pour ça que j'ai posté ce message. Alors si on peut juste me mettre sur une piste ça serai sympas.

    Merci d'avance

  13. #13
    Membre expérimenté
    Avatar de gwyohm
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Octobre 2007
    Messages
    925
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Octobre 2007
    Messages : 925
    Points : 1 333
    Points
    1 333
    Par défaut
    Bonjour,
    Je comprends pas tout ;
    visiblement le script vient de www.dhtmlgoodies.com quand on va sur ce site, il y a des démos de drag drop... faits avec prototype et scriptaculous ! et là tu présentes un code "standalone"...

    De plus il y a dans le code que tu post une fonction saveData ; ca ne fait pas ce que tu veux ?


    Enfin, je t'avais donné une piste avec les Sortables de scriptaculous pour récupérer l'ordre, tu as testé ?
    on ne dit pas "ça ne marche pas" on dit "je suis incapable de faire fonctionner correctement les outils mis à ma disposition"
    Pas de question technique par MP

Discussions similaires

  1. drag and drop d'une image d'une page web lancée depuis un webbroswer
    Par chrisledeveloppeur2 dans le forum Web & réseau
    Réponses: 3
    Dernier message: 02/01/2007, 15h33
  2. Drag and drop d'images
    Par PrinceMaster77 dans le forum Balisage (X)HTML et validation W3C
    Réponses: 2
    Dernier message: 31/05/2006, 21h53
  3. [ c# ]image deplacer durant drag and drop
    Par psykostik dans le forum Windows Forms
    Réponses: 2
    Dernier message: 03/05/2006, 09h16
  4. [WD10] Drag and drop "image..."
    Par lalilo dans le forum WinDev
    Réponses: 1
    Dernier message: 02/03/2006, 13h06

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo