Robię (z czystej ciekawości) slider. Zdjęcia w nim mają się przewijać płynnie.
HTML
<!DOCTYPE HTML> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" > <link rel="stylesheet" type="text/css" href="css/reset.css" media="screen"> <link rel="stylesheet" type="text/css" href="css/style.css" media="screen"> </head> <body> <div id="container"> <div id="galeria"> <div id="calosc"> </div> </div> </div> <script> window.onload = function(){ ladowanie(); } </script> </body> </html>
CSS
body { background:#FFF; color:#000; font-family: Arial, Helvetica, sans-serif; font-size: 13px; } #container { background:#f1f1f1 center no-repeat; margin:0 auto; padding:0; width:960px; } #galeria{ width:500px; height:300px; background:#363636 center no-repeat; margin:0 auto; overflow:hidden; } #zdjecie1{ width:500px; height:300px; background:url(../images/zdjecie1.jpg) no-repeat; float:left; } #zdjecie2{ width:500px; height:300px; background:url(../images/zdjecie2.jpg) no-repeat; float:left; } #zdjecie3{ width:500px; height:300px; background:url(../images/zdjecie3.jpg) no-repeat; float:left; } #zdjecie4{ width:500px; height:300px; background:url(../images/zdjecie4.jpg) no-repeat; float:left; } #calosc{ width:2000px; height:300px; transition-property: all; -webkit-transition-property: all; -ms-transition-property: all; -o-transition-property: all; -moz-transition-property: all; transition-duration: 1s; -webkit-transition-duration: 1s; -ms-transition-duration: 1s; -o-transition-duration: 1s; -moz-transition-duration: 1s; position:relative; right:0px; transform: translate(0,0); }
JS
function przesun(){ var calosc = document.getElementById("calosc"); if(calosc.style.transform = 'translate(0px,0px)'){ calosc.style.transform = 'translate(-500px,0px)'; } } function ladowanie(){ var calosc = document.getElementById("calosc"); calosc.onclick = function(){ przesun(); } }
Zastanawiałem się czy funkcja onclick może przesunąć element kilka razy. Wszystkie zdjęcia zamknięte są w jednym divie. Naciskam div i on się przesuwa o podaną wartość. Raz. Pewnie dlatego, że przesuwa się do podanej pozycji. Da się zrobic tak, żeby za każdym kliknięciem przesuwał się o 500px?