I have a fiddle which is working in a way that when I take it in the mobile view, the square boxes horizontally scroll.
The CSS codes which I have used for that are:
@media only screen and (max-width: 767px)
{
.product-all-contents
{
overflow-x: auto;
}
.product-contents .product{
min-width: 50.795%;
margin: 0 2%;
padding-top: 3.91%;
padding-left: 3.91%;
padding-right: 3.91%;
}
}
Problem Statement:
I am wondering what changes I should make in the fiddle so that when I hit arrows in the mobile view (as shown in the screenshot below marked by orange arrow sign) the content move towards the left and vice-versa.
I think best solution will be jQuery, scrollLeft() and scrollRight() but I am not sure how I can implement it in the fiddle.
For your problem you need a few things
Get the initial position so you can calculate the slide
let divMain = $('.product-all-contents')[0]; let position = $(divMain).children().position().left; const slideAmount = 150;
This 3 variables will be the main values for the code
Last make the listenes for the slide
$('#arrow-right').click(function() { $(divMain).animate({ scrollLeft: position + slideAmount }, 500); position += slideAmount; })
Hope this helps :>