Probleme div zoom (avec javascript)

Fermé
Xogno - 25 déc. 2010 à 17:33
 Xogno - 26 déc. 2010 à 12:04
Bonjour !

Mon but est de faire une gallerie d'images (miniatures) et que quand on passe au-dessus le carde s'agrandisse et qu'il affiche l'image taille réelle.
J'utilise donc du javascript.De ce coté là mon code marche sauf que... si un carde s'agrandit, les autres bougent aussi alors que je voudrais qu'ils demeurent immobiles :/

Vous pouvez voir le problème :
>> http://share_spot.byethost13.com/test%20site%20JESS/test.html <<

le code javascript :

var width  = 60 ;
var height = 60 ;

var zoomwidth  = 200 ;
var zoomheight = 200 ;

if (document.getElementById && document.getElementsByTagName) {
if (window.addEventListener) window.addEventListener('load', initAnims, false);
else if (window.attachEvent) window.attachEvent('onload', initAnims);
}

function initAnims() {

	
			
	//	Init size animation with memory, both directions
		var animElements = document.getElementById("resizercontainer").getElementsByTagName("div")
		for(var i=0; i<animElements.length; i++) {
			animElements[i].onmouseover = sizeChange;
			animElements[i].onmouseout  = sizeRestore;
			}

		function sizeChange() {
			if (!this.currentWidth)  this.currentWidth  = width; //if no mem is set, set it first;
			if (!this.currentHeight) this.currentHeight = height; //if no mem is set, set it first;
			doSizeChangeMem(this,this.currentWidth,zoomwidth,this.currentHeight,zoomheight,10,10,0.333);
			}

		function sizeRestore() {
			if (!this.currentWidth) return;	//avoid error if mouseout an element occurs before the mosueover
												//(e.g. the pointer already in the object when onload)
			if (!this.currentHeight) return;	//avoid error if mouseout an element occurs before the mosueover
												//(e.g. the pointer already in the object when onload)
			doSizeChangeMem(this,this.currentWidth,width,this.currentHeight,height,10,10,0.5);
			}
	
	}

//*******************

function doSizeChangeMem(elem,startWidth,endWidth,startHeight,endHeight,steps,intervals,powr) {
//Width changer with Memory 
	if (elem.sizeChangeMemInt) window.clearInterval(elem.sizeChangeMemInt);
	var actStep = 0;
	elem.style.position = "fixed";
	elem.style.zIndex  = 5;

	/*
	*  Pour etre sûr qu'il reviennent à la bonne position
	*/
	if (endWidth > startWidth) {// on aggrandi
	   elem.style.left = 0+"px";
	   elem.style.top  = 0+"px";
	}
	else {// on rétréci
	   elem.style.left = ((endWidth  - startWidth) /2)+"px";
	   elem.style.top  = ((endHeight - startHeight)/2)+"px";
	}

	   elem.sizeChangeMemInt = window.setInterval(
		function() {
			elem.currentWidth  = easeInOut(startWidth,endWidth,steps,actStep,powr);
			elem.currentHeight = easeInOut(startHeight,endHeight,steps,actStep,powr);
			
			if (!elem.style.left){
				elem.style.left = 0+"px";
				elem.style.top  = 0+"px";
			}
			else
			{
				if (!(actStep - steps) && endWidth < startWidth) {
					elem.style.left = 0+"px";
					elem.style.top  = 0+"px";
				} else {
					/*
					*  Il faut faire une fonction comme easeInOut pour calculer le left en fonction de l'étape.
					*  Comme ça à la première étape d'office le left est mis à 0, et au max pour la dernière étape.
					*/
					var actualwidth  = parseInt(elem.style.width);
					var actualheight = parseInt(elem.style.height);
					var newwidth     = parseInt(elem.currentWidth);
					var newheight    = parseInt(elem.currentHeight);
					var actualleft   = parseInt(elem.style.left);
					var actualtop    = parseInt(elem.style.top);
					var newleft      = ((actualwidth  - newwidth) /2);
					var newtop       = ((actualheight - newheight)/2);
					elem.style.left  = (actualleft + newleft)+"px";
					elem.style.top   = (actualtop  + newtop )+"px";
				}
			}
			elem.style.width  = elem.currentWidth  +"px";
			elem.style.height = elem.currentHeight +"px";
			actStep++;

			if (actStep > steps) window.clearInterval(elem.sizeChangeMemInt);
		}
		,intervals)

	elem.style.position = "";
	elem.style.zIndex = "";
		
}

//*******************

function easeInOut(minValue,maxValue,totalSteps,actualStep,powr) {
//Generic Animation Step Value Generator 
	var delta = maxValue - minValue;
	var stepp = minValue+(Math.pow(((1 / totalSteps)*actualStep),powr)*delta);
	return Math.ceil(stepp)
}

--------------------------------------------

et le (peu de) css:

/* div contenant les cadres */
#resizercontainer 
{
	width:200px;
	padding:15px;
	border:solid black 1px;
	margin:auto;
}

/* cadres */
.elem-container
{
	width:60px;
	height:60px;
	position:relative;
	top:0;
	bottom:0;
	left:0;
	margin:10px;
	padding:0px;
	background-color:gray;
}


J'espère que vous pourrez m'aider :)
Merci d'avance,

Xogno

PS: si vous savez comment faire la même chose avec des images, si vous avez le temps, n'hésitez pas à me le dire !

A voir également:

2 réponses

Up.

Personne n'a une solution svp ?
(n'hésitez pas à poser des questions si besoin)
0
re up
0
MastercroW Messages postés 1094 Date d'inscription dimanche 3 octobre 2010 Statut Membre Dernière intervention 31 mai 2019 163
Modifié par MastercroW le 25/12/2010 à 17:38
Bonsoir,
Je suis assez nul en JS, donc j'essai de te convaincre autrement, pourquoi ne pas prendre des scripts ? Sur ce site : http://blog.bouctoubou.com/13-javascripts-lightbox-images-galeries-videos/ il y a tout et n'importe quoi pour faire une mini-galerie.
Voila j'espère t'avoir aidé.
-1
Bonjour, merci de m'avoir fait connaitre lightbox.
J'ai trouvé un script que je pourrais utiliser mais j'aimerais quand même trouver la solution a mon problème :P comme programmeur (débutant en JS) j'aimerais bien savoir comment résoudre le problème.
0