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
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login