Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scrolling through multiple DIV elements

For example let's say that I have a div element with 100% width and 100px height. Inside that div I have 6 div elements floated left, with overflow-x enabled. What I want to achieve is, that user can scroll through loop of these divs (so that last div element is followed by first - infinite loop).

Any idea how to approach?

enter image description here

like image 484
user1784025 Avatar asked Dec 24 '22 03:12

user1784025


1 Answers

You can use jQuery insertAfter and insertBefore functions

$('.next').click(function(){
     var last = $('#parent').find('div').last();
    $('#parent').find('div').first().insertAfter(last);
});

$('.prev').click(function(){
     var first= $('#parent').find('div').first();
    $('#parent').find('div').last().insertBefore(first);
});

Here is the DEMO

like image 110
Ashkan Mobayen Khiabani Avatar answered Jan 06 '23 09:01

Ashkan Mobayen Khiabani