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
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
.slideIn{
overflow:hidden;
width:500px;
height:300px;
background-color:green;
position:relative;
}
.slideIn div{
width:100%;
height:300px;
position:absolute;
display:none;
}
</style>
<script type="text/javascript">
function Create(deep) {
var objectClone = new this.constructor();
for (var property in this)
if (!deep)
objectClone[property] = this[property];
else if (typeof this[property] == 'object')
objectClone[property] = this[property].Create(deep);
else
objectClone[property] = this[property];
return objectClone;
}
Object.prototype.Create = Create;
var SlideIn = {
//Id du conteneur
idObj : null
,
timer : null
,
from : null
,
to : null
,
direction : null
,
//Tableau d'élément a déplacé
elementToSlide : new Array()
,
//Index de l'élément en cours
currentIndex : 0
,
$:function(element){
return document.getElementById(element);
}
,
SlideToLeft : function(){
if(this.timer != null){
clearTimeout(this.timer);
this.timer = null;
}
//On vérifit la direction pour initialiser le positionnement
if(this.direction != 'left'){
this.direction = 'left';
this.Positionne();
}
//Si le timer n'est pas finit on détruit l'ancienne div
if(parseInt(this.from.style.left) == Number.NaN || (parseInt(this.from.offsetWidth) + parseInt(this.from.style.left))> 0){
this.from.style.left = parseInt(this.from.style.left) - 20 + "px";
this.to.style.left =parseInt(this.to.style.left) - 20 + "px";
//alert((parseInt(this.$(from).offsetWidth) + parseInt(this.$(from).style.left)));
var me = this ;
this.timer = setTimeout(function(){me.SlideToLeft()},30);
}
else{
clearTimeout(this.timer);
this.timer = null;
this.currentIndex = (this.currentIndex == (this.elementToSlide.length-1)) ? 0:this.currentIndex + 1;
this.$('debug').innerHTML = this.currentIndex;
this.Positionne();
//TimerRunning = false;
//$(smallMenu).parentNode.removeChild($(smallMenu));
}
}
,
SlideToRight : function(){
if(this.timer != null){
clearTimeout(this.timer);
this.timer = null;
}
if(this.direction != 'right'){
this.direction = 'right';
this.Positionne();
}
//Si le timer n'est pas finit on détruit l'ancienne div
if(parseInt(this.from.style.left) == Number.NaN || parseInt(this.from.style.left) < parseInt(this.from.offsetWidth)){
this.from.style.left = parseInt(this.from.style.left) + 20 + "px";
this.to.style.left =parseInt(this.to.style.left) + 20 + "px";
//alert((parseInt(this.$(from).offsetWidth) + parseInt(this.$(from).style.left)));
var me = this ;
this.timer = setTimeout(function(){me.SlideToRight()},30);
}
else{
clearTimeout(this.timer);
this.timer = null;
this.currentIndex = (this.currentIndex == 0) ? this.elementToSlide.length-1:this.currentIndex - 1;
this.$('debug').innerHTML = this.currentIndex;
this.Positionne();
}
}
,
//Fonction initialisant le tableau en positionnant tous les éléments :)
Positionne : function(){
if(this.direction == 'left'){
//On vérifit que l'on est pas a la fin sinon le premier devient le dernier
if(this.currentIndex == this.elementToSlide.length-1){
//récupération des éléments :
this.from = this.$(this.elementToSlide[this.currentIndex]);
this.to = this.$(this.elementToSlide[0]); //Premier élément
}
else{
this.from = this.$(this.elementToSlide[this.currentIndex]);
this.to = this.$(this.elementToSlide[this.currentIndex + 1]);
}
this.from.style.display = "block" ;
this.from.style.left = 0 + "px";
this.to.style.left = this.from.offsetWidth + "px";
this.to.style.display = "block"
}
else{
if(this.currentIndex == 0){
this.from = this.$(this.elementToSlide[this.currentIndex]);
this.to = this.$(this.elementToSlide[this.elementToSlide.length-1]); // dernier élément
}
else{
this.from = this.$(this.elementToSlide[this.currentIndex]);
this.to = this.$(this.elementToSlide[this.currentIndex-1]);
}
this.from.style.display = "block" ;
this.from.style.left = 0 + "px";
this.to.style.left = - (this.from.offsetWidth )+ "px";
this.to.style.display = "block";
}
}
}
var newSlide = SlideIn;
newSlide.elementToSlide.push('la1');
newSlide.elementToSlide.push('la2');
newSlide.elementToSlide.push('la3');
newSlide.elementToSlide.push('la4');
newSlide.elementToSlide.push('la5');
newSlide.elementToSlide.push('la6');
var newSlide2 = newSlide.Create();
newSlide2.elementToSlide.push('la11');
newSlide2.elementToSlide.push('la22');
newSlide2.elementToSlide.push('la33');
newSlide2.elementToSlide.push('la44');
newSlide2.elementToSlide.push('la55');
newSlide2.elementToSlide.push('la66');
</script>
</head>
<body>
<div class="slideIn">
<div id="la1" style="background-color:red;left:0px;"></div>
<div id="la2" style="background-color:blue;left:0px;">la</div>
<div id="la3" style="background-color:#ccc;left:0px;">la</div>
<div id="la4" style="background-color:yellow;left:0px;"></div>
<div id="la5" style="background-color:black;left:0px;">la</div>
<div id="la6" style="background-color:pink;left:0px;">la</div>
</div>
<input type="button" value="gauche" onclick="newSlide.SlideToLeft()">
<input type="button" value="droite" onclick="newSlide.SlideToRight()">
<span id="debug"></span>
<div class="slideIn">
<div id="la11" style="background-color:red;left:0px;"></div>
<div id="la22" style="background-color:blue;left:0px;">la</div>
<div id="la33" style="background-color:#ccc;left:0px;">la</div>
<div id="la44" style="background-color:yellow;left:0px;"></div>
<div id="la55" style="background-color:black;left:0px;">la</div>
<div id="la66" style="background-color:pink;left:0px;">la</div>
</div>
<input type="button" value="gauche" onclick="newSlide2.SlideToLeft()">
<input type="button" value="droite" onclick="newSlide2.SlideToRight()">
</body>
</html> |
Partager