Skip to content
  • Recent
  • Tags
  • Popular
  • Users
  • Search
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

Lay Theme Forum

  1. Home
  2. General Discussion
  3. Random Intro Image Working JS

Random Intro Image Working JS

Scheduled Pinned Locked Moved General Discussion
5 Posts 3 Posters 976 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N
    N
    Nemo
    wrote on last edited by
    #1

    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 !

    1 Reply Last reply
    0
    • RichardR
      RichardR
      Richard
      Global Moderator
      wrote on last edited by
      #2

      Dear @Nemo

      Thank you so much for posting, awesome!
      This will i'm sure help others in the future :)

      Thank you for using Lay Theme & helping the community.

      Have a wonderful day,

      Sincerely
      Richard

      1 Reply Last reply
      0
      • N
        N
        Nemo
        wrote on last edited by
        #3

        Hello Richard,

        Yes I posted it in another thread ! You can delete this one !

        1 Reply Last reply
        0
        • RichardR
          RichardR
          Richard
          Global Moderator
          wrote on last edited by
          #4

          Dear @Nemo

          Thanks once again :)

          Best wishes
          Richard

          1 Reply Last reply
          0
          • C
            C
            chris.vuko
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0

            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
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            Online Users
            L
            lstark
            Forgot your key, lost your files, need a previous Lay Theme or Addon version? Go to www.laykeymanager.com
            laytheme.com
            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Recent
            • Tags
            • Popular
            • Users
            • Search