Je travail sur un script pour faire zoom sur les images, et le probleme est que je calcule la taille désiré pour le zoom / dézoom à partir des dimensions de l'image, seulement que si quelqu'un passe la souris dessus et s'enleve ou enclanche le dézoom desuite apres avoir enclancher le zoom, les dimensions desiré de départ (etit dimensions) et fin (grand dimensions) sont alors modifiés, testé ici:
http://www.herpfrance.com/Web/untitled.html
CODE
window.onload = startfunc;
function startfunc(){
divi = document.getElementById("atlas");
images = divi.getElementsByTagName("img");
for(i=0;i<images.length;i++){
images[i].onmouseover = function(){
ratioW = this.width * 0.1515;
ratioH = this.height * 0.1515;
zoomin(this);
}
images[i].onmouseout = function(){
zoomout(this);
}
}
}
function zoomin(id) {
widthactuel = id.width;
desiredwidth = (widthactuel * 3);
heightactuel = id.height;
desiredheight = (heightactuel * 3);
if(widthactuel < desiredwidth){
i = widthactuel;
p = heightactuel;
id.style.zIndex = 1;
doStep1();
}
function doStep1() {
if(i < desiredwidth) {
id.style.width = (i + 'px');
id.style.height = (p + 'px');
i = i+ ratioW;
p = p+ ratioH;
setTimeout(doStep1,1);
}
}
}
function zoomout(id) {
widthactuel = id.width;
desiredwidth = (widthactuel / 3);
heightactuel = id.height;
desiredheight = (heightactuel / 3);
if(widthactuel > desiredwidth){
i = widthactuel;
p = heightactuel;
id.style.zIndex = 0;
doStep2();
}
function doStep2() {
if(i > desiredwidth) {
id.style.width = (i + 'px');
id.style.height = (p + 'px');
i = i-ratioW;
p = p-ratioH;
setTimeout(doStep2,1);
}
}
}
function startfunc(){
divi = document.getElementById("atlas");
images = divi.getElementsByTagName("img");
for(i=0;i<images.length;i++){
images[i].onmouseover = function(){
ratioW = this.width * 0.1515;
ratioH = this.height * 0.1515;
zoomin(this);
}
images[i].onmouseout = function(){
zoomout(this);
}
}
}
function zoomin(id) {
widthactuel = id.width;
desiredwidth = (widthactuel * 3);
heightactuel = id.height;
desiredheight = (heightactuel * 3);
if(widthactuel < desiredwidth){
i = widthactuel;
p = heightactuel;
id.style.zIndex = 1;
doStep1();
}
function doStep1() {
if(i < desiredwidth) {
id.style.width = (i + 'px');
id.style.height = (p + 'px');
i = i+ ratioW;
p = p+ ratioH;
setTimeout(doStep1,1);
}
}
}
function zoomout(id) {
widthactuel = id.width;
desiredwidth = (widthactuel / 3);
heightactuel = id.height;
desiredheight = (heightactuel / 3);
if(widthactuel > desiredwidth){
i = widthactuel;
p = heightactuel;
id.style.zIndex = 0;
doStep2();
}
function doStep2() {
if(i > desiredwidth) {
id.style.width = (i + 'px');
id.style.height = (p + 'px');
i = i-ratioW;
p = p-ratioH;
setTimeout(doStep2,1);
}
}
}