javascript - How to make the slider move right and left alternatively -



javascript - How to make the slider move right and left alternatively -

the slider have moving left side automatically , 1 time reaches moves first slider , repeats.

all wanted create slider right left , left right alternatively.

how can ?

here fiddle.

here css

#slideshow { position: relative; width: 640px; height: 310px; padding: 15px; border: 1px solid #ddd; margin: 0 auto 2em; background: #fff; background: -webkit-linear-gradient(#fff, #fff 20%, #eee 80%, #ddd); background: -moz-linear-gradient(#fff, #fff 20%, #eee 80%, #ddd); background: -ms-linear-gradient(#fff, #fff 20%, #eee 80%, #ddd); background: -o-linear-gradient(#fff, #fff 20%, #eee 80%, #ddd); background: linear-gradient(#fff, #fff 20%, #eee 80%, #ddd); -webkit-border-radius: 2px 2px 2px 2px; -moz-border-radius: 2px 2px 2px 2px; border-radius: 2px 2px 2px 2px; -webkit-box-shadow: 0 0 3px rgba(0,0,0, 0.2); -moz-box-shadow: 0 0 3px rgba(0,0,0, 0.2); box-shadow: 0 0 3px rgba(0,0,0, 0.2); }

as don't have thought in javascript not able have steps.

your current animation keyframes:

@-webkit-keyframes slider { 0%, 20%, 100% { left: 0 } 25%, 45% { left: -100% } 50%, 70% { left: -200% } 75%, 95% { left: -300% } }

it goes 0 -100% -200% .. -300% , 0.

you can alter this:

@-webkit-keyframes slider { 0%, 20%, 100% { left: 0 } 25%, 45% { left: -100% } 50%, 70% { left: 0 } 75%, 95% { left: -100% } }

here got , forth between 0 , -100%.

show more 2 slides:

add classes slides able hide , show them , created these keyframes so:

@-webkit-keyframes slider1 { 0%, 20%, 100% { opacity: 1; display: block; visibility: visible; } 25%, 45% { opacity: 0; display: none; visibility: hidden; } 50%, 70% { opacity: 0; display: none; visibility: hidden; } 75%, 95% { opacity: 0; display: none; visibility: hidden; } } @-webkit-keyframes slider2 { 0%, 20%, 100% { opacity: 0; display: none; visibility: hidden; } 25%, 45% { opacity: 1; display: block; visibility: visible; } 50%, 70% { opacity: 0; display: none; visibility: hidden; } 75%, 95% { opacity: 0; display: none; visibility: hidden; } } @-webkit-keyframes slider3 { 0%, 20%, 100% { opacity: 0; display: none; visibility: hidden; } 25%, 45% { opacity: 0; display: none; visibility: hidden; } 50%, 70% { opacity: 1; display: block; visibility: visible; } 75%, 95% { opacity: 0; display: none; visibility: hidden; } } @-webkit-keyframes slider4 { 0%, 20%, 100% { opacity: 0; display: none; visibility: hidden; } 25%, 45% { opacity: 0; display: none; visibility: hidden; } 50%, 70% { opacity: 0; display: none; visibility: hidden; } 75%, 95% { opacity: 1; display: block; visibility: visible; } }

now need position slide 3 1 , 4 2 is, since have fixed width used position: relative; , add together animation keyframes (don't forget other prefixes)

#slideshow .slide_1 { -webkit-animation: slider1 32s infinite; } #slideshow .slide_2 { -webkit-animation: slider2 32s infinite; } #slideshow .slide_3 { position: relative; left: -1280px; -webkit-animation: slider3 32s infinite; } #slideshow .slide_4 { position: relative; left: -1280px; -webkit-animation: slider4 32s infinite; }

the finished fiddle

javascript jquery html css slider

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -