Hej, Mam taki kawałek slidera, który działa na przyciski:
<div class="featured-slider">
<div class="diy-slideshow">
<figure class="show">
<img src="images/palacyk_brama.jpg" width="100%" />
</figure>
<figure>
<img src="images/palacyk_front.jpg" width="100%" />
</figure>
<figure>
<img src="images/palacyk_basen.jpg" width="100%" />
</figure>
<figure>
<img src="images/palacyk_staw.jpg" width="100%" />
</figure>
<figure>
<img src="images/palacyk_garaze.jpg" width="100%" />
</figure>
<figure>
<img src="images/palacyk_widok.jpg" width="100%" />
</figure>
<span class="prev">«</span>
<span class="next">»</span>
</div>
</div>
I taki kawałek js do tego:
<script type="text/javascript">
(function(){
var counter = 0, // to keep track of current slide
$items = document.querySelectorAll('.diy-slideshow figure'), // a collection of all of the slides, caching for performance
numItems = $items.length; // total number of slides
// this function is what cycles the slides, showing the next or previous slide and hiding all the others
var showCurrent = function(){
var itemToShow = Math.abs(counter%numItems);// uses remainder (aka modulo) operator to get the actual index of the element to show
// remove .show from whichever element currently has it
// http://stackoverflow.com/a/16053538/2006057
[].forEach.call( $items, function(el){
el.classList.remove('show');
});
// add .show to the one item that's supposed to have it
$items[itemToShow].classList.add('show');
};
// add click events to prev & next buttons
document.querySelector('.next').addEventListener('click', function() {
counter++;
showCurrent();
}, false);
document.querySelector('.prev').addEventListener('click', function() {
counter--;
showCurrent();
}, false);
})();
</script>
Chciałbym aby miał te przyciski, ale jak nikt nie klika, to żeby latał z automatu, co 5 sek slajd an przyklad..
Próbowałem symulować jakoś kliknięcie w next, ale działa tylko 1 raz.
setTimeout( function() { $( '.next' ).trigger( 'click' ) }, 5000 );
Dla kogoś, kto zna chociaz podstawy js, to pewnie będzie bułka z masłem ![]()













