-
AuthorPosts
-
June 7, 2020 at 2:24 am #1220093
Hi,
I’m using a product slider on my home page. This slider has 4 columns.
My question is: which code do I need to add to make it 3 columns on tablets and 2 columns on mobiles?
If needed, you can find a link and credentials to my website in private content.
Thanks a lot!June 14, 2020 at 10:53 pm #1222527Hey fcp,
Sorry for the late reply, I didn’t find a solution to do this with an Enfold “filter” or “hook”, but I was able to write a script that seems to work. First I added a custom ID to your home page product sliderfrontpage-product-slider
because we don’t want this running amok.
Then I added this script to your child theme functions.phpfunction custom_shop_columns_script(){ ?> <script> (function($){ $(document).ready(function(){ var width = $(window).width() if((width >= 768) && (width <= 1024)) { $('#frontpage-product-slider.template-shop.avia-content-slider').removeClass('shop_columns_4').addClass('shop_columns_3'); } else if((width <= 767)) { $('#frontpage-product-slider.template-shop.avia-content-slider').removeClass('shop_columns_4').addClass('shop_columns_2'); } else {} }); })(jQuery); </script> <?php } add_action('wp_footer', 'custom_shop_columns_script');
Then I added this css to your Quick CSS
#frontpage-product-slider.shop_columns_3 .products .product { width: 31.6% !important; } #frontpage-product-slider.shop_columns_3 .products .product:nth-child(4) { display: none !important; } .responsive #top #main #frontpage-product-slider.shop_columns_2 .products .product { margin: 0 1% 1% 0 !important; width: 49% !important; }
I had to disable your Autoptimize plugin because it’s cache was making it hard to test this, but it seems to work now. Please clear your browser cache and check.
Please note, if you test on a desktop by changing your window size, you will have to reload the page because the script works on page load and not window resize.Best regards,
MikeJune 18, 2020 at 12:10 am #1223529Hi Mike,
First, thanks a lot for your work on this!!!
You’re right, it works, but I’m a little bit annoyed by the fact that the script doesn’t work on window resize, because it could cause some display issues for users on a desktop…I was thinking about another solution: I could simply create two similar sliders on my home page, one with four products but hidden on mobiles and tablets, and the other with three products but hidden on desktops.
My question is: do you think using this method could add loading time for my main page? If you think so, I would prefer to use your method.Last question: did you modify any setting in Autoptimize plugin? Because I’m using it to fix this theme issue: https://kriesi.at/support/topic/privacy-cookies-enfold-documentation/
One more time, thanks a lot Mike! :-)
June 20, 2020 at 3:08 pm #1224273Hi,
Sorry for the late reply, I’m not sure how this could cause some display issues for users on a desktop, without “window resize”. Do you believe your users are loading your site on a desktop and then resizing the window?
I believe that using two different elements for different screen sizes would not add much to the loading time because the element is already loading so the difference is just the small amount of text that is in the element.
So I would recommend this approach.
Yes, I had disabled your Autoptimize plugin because its cache was making it hard to test the above solution, I wrote about this above, but I have re-enabled it now, sorry for the confusion.Best regards,
MikeJune 20, 2020 at 3:50 pm #1224277Hi Mike,
Thanks a lot for your reply.
You’re right, maybe I worry for nothing :-)If you recommend to use two different elements, I will do it! Nevertheless, I will keep your code somewhere in a note ;-)
About this, where did you add the CSS code above? I can not find it in Enfold > General styling > Quick CSS and in my child theme style.css…Thanks a lot!
June 20, 2020 at 5:37 pm #1224290Hi,
Thanks, the css is in your WordPress > Customize > Additional CSS I had moved it a couple of times until I realized the Autoptimize cache was giving me some trouble.
Anyways, please let us know if you need further help with setting up the two elements to show on different devices.Best regards,
MikeJuly 11, 2020 at 1:14 am #1229507Hi Mike,
So I doubled my slider on my homepage and it seems to works normally.
This topic can be closed.
Thanks a lot for your help!July 11, 2020 at 4:43 pm #1229649Hi fcp,
Great :)
Glad you got it working for you!
We are closing the thread.
If you need further assistance please let us know in a new one.
Best regards,
Victoria -
AuthorPosts
- The topic ‘Responsive Products Slider’ is closed to new replies.