hi guys. I'm trying to make a simple - really simple - slide with text.
please, don't say "use jquery". I wanna make it by myself for personal reasons ;)
My thing was that: I have some <div class="pippo"> one near the other one into a main <div id="main"> overflowed.
They have the {float:left} property so they have an incremental margin
This is the code I made (the animation will be make later, for now there are two buttons):
<div id="main"> <div id="primo" class="pluto"> Questo e' il primo div, non c'e' molto da dire. funzia sempre </div> <div class="pippo" style="background:#fff;color:#000"> xxx </div> <div class="pippo"> xxx </div> <div class="pippo"> xxx </div> </div>
<script>
// mxv is the width of every slide;
// global is used to move divs left (if > 0) or right (if < 0) from starting position
var global=0, mxw=400;
// the first div:
ciccio=document.getElementById("primo");
// the next divs: is an array:
ppk=document.getElementById("main").getElementsByClassName("pippo");
// every div has an incremental margin, so initialize them
for (var i=0;i<ppk.length;i++){
ppk[i].style.marginLeft = (i+1)*mxw + "px";
// writing their actual margin for developing use
ppk[i].innerHTML="margin: " + (i+1)*mxw;
}
// when clicked one of the buttons, this function is called:
// lefting: if set to 0 divs move to right, else they move to left
// passo: how many pixel every movement
function Slide(lefting,passo){
if (lefting) global--;
else global++;
// full movement of first div
var delta = global*passo;
ciccio.style.marginLeft = delta + "px";
// full movement of next divs
for (var i=0;i<ppk.length;i++){
ppk[i].style.marginLeft = delta + (i+1)*mxw + "px";
// writing their actual margin for developing use
ppk[i].innerHTML="margin: " + (delta + (i+1)*mxw);
}
}
</script>
</body>
</html>
the 1st div disappear on reaching the left margin "220px", the second at "420px". What the hell is happening???