Random Intro Image Working JS
-
Hello,
Since I finally managed to do it and some people are asking it, here's the JS code I used :
<script> var images = ['https://img.webmd.com/dtmcms/live/webmd/consumer_assets/site_images/article_thumbnails/other/cat_relaxing_on_patio_other/1800x1200_cat_relaxing_on_patio_other.jpg', 'https://ichef.bbci.co.uk/news/976/cpsprodpb/12A9B/production/_111434467_gettyimages-1143489763.jpg', 'https://cdnuploads.aa.com.tr/uploads/Contents/2020/05/14/thumbs_b_c_88bedbc66bb57f0e884555e8250ae5f9.jpg?v=140708', ]; var randomImage = Math.floor(Math.random() * 3) window.laytheme.on("newpageshown", function(layoutObj, type, obj){ if(type == "page" && obj.id == 72){ jQuery("body").css("background-image", "url('" + images[randomImage] +"')"); } else { jQuery("body").css("background-image", "") } }); </script>
You just have to change the url of the images, the number of images and the id of the corresponding page.
Enjoy !
-
Hey @Nemo!
Thanks for sharing your solution!
I'm on it, but I still have some issues. Maybe you have a small hint?
Instead of having random background images I want to have just random images placed in a separate row. Do I need to give the image I place an id or do I need to insert code via "+more > +html". Also, do I need to change sth for "background-image"?
Thanks for your help!
Best,
Christian
Before you post:
Use the Search Feature. Maybe there is already a solution to your issue.
1. Update Lay Theme and all Lay Theme Addons
2. Disable all Plugins
3. Go to Lay Options → Custom CSS & HTML, click "Turn Off All Custom Code ", click "Save Changes"
4. When using a WordPress Cache plugin, disable it or clear your cache.
Now see if your problem solved itself.
Go here, see if your problem is listed here:
Troubleshooting
When you post:
1. Post a link to where the problem is
2. If the problem is difficult to explain, post screenshots / link to a video to explain it
I don't answer or check forum DMs, please just post on the forum.