Bonjour,
je souhaite réalisé deux défilements d'images de partenaires. J'ai bien les 2 barres que je souhaite mais le souci c'est qu'il y en un qui reste figé. Si quelqu'un pouvait m'aider car je ne maîtrise pas vraiment le javascript, seul outil dont j'ai à ma disposer pour réaliser mon projet. Merci davance pour vos réponses!
Voici le code:
<script type="text/javascript">
<!--
// ********** User Defining Area **********
data2=[
["1.png","",""],
["2.png","",""],
["3.png","",""],
["4.png","",""],
["5.png","",""],
["6.png","",""],
["7.png","",""],
["8.png","",""],
["9.png","",""]//pas de virgule pour le dernier élément
]
imgPlaces2=7 // nombre d'images visibles
imgWidth2=100 // taille en largueur des images
imgHeight2=45 // taille en hauteur des images
imgSpacer2=16 // espace entre les images
dir2=0 // direction pour le défilement 0 = gauche, 1 = droite
newWindow=1 // ouverture de nouvelle fenetre au clic sur image 0=non et 1=oui
// ********** Fin de la zone de définition des différents paramètres **********
moz2=document.getElementById&&!document.all
step2=1
timer2=""
speed2=10
nextPic2=0
initPos2=new Array()
nowDivPos2=new Array()
function initHIS2(){
for(var i=0;i<imgPlaces2+1;i++){ // ccréation des images
newImg2=document.createElement("IMG")
newImg2.setAttribute("id","pic_"+i)
newImg2.setAttribute("src","")
newImg2.style.position="absolute"
newImg2.style.width=imgWidth2+"px"
newImg2.style.height=imgHeight2+"px"
newImg2.style.border=0
newImg2.alt=""
newImg2.i=i
newImg2.onclick=function(){his2Win(data2[this.i][2])}
document.getElementById("display_area2").appendChild(newImg2)
}
containerEL2=document.getElementById("his2container")
displayArea2=document.getElementById("display_area2")
pic02=document.getElementById("pic_0")
containerBorder2=(document.compatMode=="CSS1Compat"?0:parseInt(containerEL2.style.borderWidth)*2)
containerWidth2=(imgPlaces2*imgWidth2)+((imgPlaces2-1)*imgSpacer2)
containerEL2.style.width=containerWidth2+(!moz2?containerBorder2:"")+"px"
containerEL2.style.height=imgHeight2+(!moz2?containerBorder2:"")+"px"
displayArea2.style.width=containerWidth2+"px"
displayArea2.style.clip="rect(0,"+(containerWidth2+"px")+","+(imgHeight2+"px")+",0)"
displayArea2.onmouseover=function(){stopHIS2()}
displayArea2.onmouseout=function(){scrollHIS2()}
imgPos2= -pic02.width
for(var i=0;i<imgPlaces2+1;i++){
currentImage2=document.getElementById("pic_"+i)
if(dir2==0){imgPos2+=pic02.width+imgSpacer2} // if left
initPos2[i]=imgPos2
if(dir2==0){currentImage2.style.left=initPos2[i]+"px"} // if left
if(dir2==1){ // if right
document.getElementById("pic_"+[(imgPlaces2-i)]).style.left=initPos2[i]+"px"
imgPos2+=pic02.width+imgSpacer2
}
if(nextPic2==data2.length){nextPic2=0}
currentImage2.src=data2[nextPic2][0]
currentImage2.alt=data2[nextPic2][1]
currentImage2.i=nextPic2
currentImage2.onclick=function(){his2Win(data2[this.i][2])}
nextPic2++
}
scrollHIS2()
}
timer2=""
function scrollHIS2(){
clearTimeout(timer2)
for(var i=0;i<imgPlaces2+1;i++){
currentImage2=document.getElementById("pic_"+i)
nowDivPos2[i]=parseInt(currentImage2.style.left)
if(dir2==0){nowDivPos2[i]-=step2}
if(dir2==1){nowDivPos2[i]+=step2}
if(dir2==0&&nowDivPos2[i]<= -(pic02.width+imgSpacer2) || dir2==1&&nowDivPos2[i]>containerWidth2){
if(dir2==0){currentImage2.style.left=containerWidth2+imgSpacer2+"px"}
if(dir2==1){currentImage2.style.left= -pic02.width-(imgSpacer2*2)+"px"}
if(nextPic2>data2.length-1){nextPic2=0}
currentImage2.src=data2[nextPic2][0]
currentImage2.alt=data2[nextPic2][1]
currentImage2.i=nextPic2
currentImage2.onclick=function(){his2Win(data2[this.i][2])}
nextPic2++
}
else{
currentImage2.style.left=nowDivPos2[i]+"px"
}
}
timer2=setTimeout("scrollHIS2()",speed2)
}
function stopHIS2(){
clearTimeout(timer2)
}
function his2Win(loc){
if(loc==""){return}
if(newWindow==0){
location=loc
}
else{
//window.open(loc)
newin2=window.open(loc,'win1','left=430,top=340,width=800,height=100') // utlisation pour des tailles et position spécifiques de fenêtre
newin2.focus()
}
}
// add onload="initHIS2()" to the opening BODY tag
// -->
</script>
<script type="text/javascript">
<!--
// ********** User Defining Area **********
data=[
["a.png","",""],
["b.png","",""],
["c.png","",""],
["d.png","",""],
["e.png","",""],
["f.png","",""],
["g.png","",""],
["h.png","",""],
["i.png,"",""],
["j.png","1",""]//pas de virgule pour le dernier élément
]
imgPlaces=7 // nombre d'images visibles
imgWidth=100 // taille en largueur des images
imgHeight=45 // taille en hauteur des images
imgSpacer=16 // espace entre les images
dir=0 // direction pour le défilement 0 = gauche, 1 = droite
newWindow=1 // ouverture de nouvelle fenetre au clic sur image 0=non et 1=oui
// ********** Fin de la zone de définition des différents paramètres **********
moz=document.getElementById&&!document.all
step=1
timer=""
speed=10
nextPic=0
initPos=new Array()
nowDivPos=new Array()
function initHIS3(){
for(var i=0;i<imgPlaces+1;i++){ // ccréation des images
newImg=document.createElement("IMG")
newImg.setAttribute("id","pic_"+i)
newImg.setAttribute("src","")
newImg.style.position="absolute"
newImg.style.width=imgWidth+"px"
newImg.style.height=imgHeight+"px"
newImg.style.border=0
newImg.alt=""
newImg.i=i
newImg.onclick=function(){his3Win(data[this.i][2])}
document.getElementById("display_area").appendChild(newImg)
}
containerEL=document.getElementById("his3container")
displayArea=document.getElementById("display_area")
pic0=document.getElementById("pic_0")
containerBorder=(document.compatMode=="CSS1Compat"?0:parseInt(containerEL.style.borderWidth)*2)
containerWidth=(imgPlaces*imgWidth)+((imgPlaces-1)*imgSpacer)
containerEL.style.width=containerWidth+(!moz?containerBorder:"")+"px"
containerEL.style.height=imgHeight+(!moz?containerBorder:"")+"px"
displayArea.style.width=containerWidth+"px"
displayArea.style.clip="rect(0,"+(containerWidth+"px")+","+(imgHeight+"px")+",0)"
displayArea.onmouseover=function(){stopHIS3()}
displayArea.onmouseout=function(){scrollHIS3()}
imgPos= -pic0.width
for(var i=0;i<imgPlaces+1;i++){
currentImage=document.getElementById("pic_"+i)
if(dir==0){imgPos+=pic0.width+imgSpacer} // if left
initPos[i]=imgPos
if(dir==0){currentImage.style.left=initPos[i]+"px"} // if left
if(dir==1){ // if right
document.getElementById("pic_"+[(imgPlaces-i)]).style.left=initPos[i]+"px"
imgPos+=pic0.width+imgSpacer
}
if(nextPic==data.length){nextPic=0}
currentImage.src=data[nextPic][0]
currentImage.alt=data[nextPic][1]
currentImage.i=nextPic
currentImage.onclick=function(){his3Win(data[this.i][2])}
nextPic++
}
scrollHIS3()
}
timer=""
function scrollHIS3(){
clearTimeout(timer)
for(var i=0;i<imgPlaces+1;i++){
currentImage=document.getElementById("pic_"+i)
nowDivPos[i]=parseInt(currentImage.style.left)
if(dir==0){nowDivPos[i]-=step}
if(dir==1){nowDivPos[i]+=step}
if(dir==0&&nowDivPos[i]<= -(pic0.width+imgSpacer) || dir==1&&nowDivPos[i]>containerWidth){
if(dir==0){currentImage.style.left=containerWidth+imgSpacer+"px"}
if(dir==1){currentImage.style.left= -pic0.width-(imgSpacer*2)+"px"}
if(nextPic>data.length-1){nextPic=0}
currentImage.src=data[nextPic][0]
currentImage.alt=data[nextPic][1]
currentImage.i=nextPic
currentImage.onclick=function(){his3Win(data[this.i][2])}
nextPic++
}
else{
currentImage.style.left=nowDivPos[i]+"px"
}
}
timer=setTimeout("scrollHIS3()",speed)
}
function stopHIS3(){
clearTimeout(timer)
}
function his3Win(loc){
if(loc==""){return}
if(newWindow==0){
location=loc
}
else{
//window.open(loc)
newin=window.open(loc,'win1','left=430,top=340,width=800,height=100') // utlisation pour des tailles et position spécifiques de fenêtre
newin.focus()
}
}
// add onload="initHIS3()" to the opening BODY tag
// -->
</script>
<script type="text/javascript">
window.onload = function (){
initHIS3();
initHIS2();
}
</script>
</head>
<body>
<DIV id="his2container" style="position:relative; width:0px;height:0px; border:1px solid #5F5F5F;overflow:hidden; background-color:#ffffff">
<div id="display_area2" style="position:absolute; left:0; top:0; width:0px; height:0px; clip:rect(0,0,0,0)"></div>
</DIV>
<!-- Contenu Menu Horizontal-->
<DIV id="his3container" style="position:relative; width:0px;height:0px; border:1px solid #5F5F5F;overflow:hidden; background-color:#ffffff">
<div id="display_area" style="position:absolute; left:0; top:0; width:0px; height:0px; clip:rect(0,0,0,0)"></div>
</DIV><br/>