Skip to content
  • Recent
  • Tags
  • Popular
  • Users
  • Search
Skins
  • Light
  • 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 Video Backgrounds on Homepage

Random Video Backgrounds on Homepage

Scheduled Pinned Locked Moved General Discussion
13 Posts 6 Posters 705 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.
  • S Offline
    S Offline
    spontans
    wrote on Aug 14, 2017, 11:26 AM last edited by
    #1

    Hi Marius,

    I'm trying to set a video background for my homepage that will play a random video each time.

    My temporary website url: http://82.80.209.62/~cleanpla/sasha2017

    I've added a video background via the gridder, and I run this script each time the homepage loads:

    if($("body").hasClass("slug-home2")) {
    var videosrc = Math.floor(Math.random() * 6) + 1;
    var homeurl = 'http://82.80.209.62/~cleanpla/sasha2017/videobg/';
    videopath = homeurl+videosrc+'.mp4';
    $('video').attr('preload', videopath);
    $('video source').attr('src', videopath);
    }

    uder the:
    Frontend.GlobalEvents.on("newpageshown", function(layoutObj, type, obj){}
    event.

    Everything works smooth and fast in Chrome, but in Safari there is usually a long lag with showing and starting a video (when going back to homepage from Info/Shop/Works page.

    Is there anything I can do to preload the videos faster in safari? or maybe there is a problem with my script or the event that I'm launching it at?

    Thanks in advance for any help.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mariusjopen
      Global Moderator
      wrote on Aug 14, 2017, 4:35 PM last edited by
      #2

      Hi Spontans,

      Your script looks fine to me. But give me a day to check and I will get back to you.

      Best!

      Marius

      www.mariusjopen.world

      1 Reply Last reply
      0
      • S Offline
        S Offline
        spontans
        wrote on Aug 14, 2017, 6:48 PM last edited by
        #3

        Thank you Marius, I love you!

        1 Reply Last reply
        1
        • A Offline
          A Offline
          arminunruh
          Global Moderator
          wrote on Aug 15, 2017, 3:13 PM last edited by
          #4

          Hey spontanus

          <video data-ar="0.75" preload="http://82.80.209.62/~cleanpla/sasha2017/videobg/3.mp4" muted="" autoplay="" loop=""><source src="http://82.80.209.62/~cleanpla/sasha2017/videobg/3.mp4" type="video/mp4"></video>

          Not sure if preload="yoururl" is valid html. Maybe try just preload without ="yoururl"

          1 Reply Last reply
          0
          • S Offline
            S Offline
            spontans
            wrote on Aug 15, 2017, 9:02 PM last edited by
            #5

            ok, so the following steps are what i need to do?

            1. disable the video background feature
            2. insert this this html in gridder (maybe with some really light, 1 sec video..)
            3. change the preload and source attributes with my randomizer script on "newpageshown"
            1 Reply Last reply
            0
            • A Offline
              A Offline
              arminunruh
              Global Moderator
              wrote on Aug 16, 2017, 10:10 AM last edited by
              #6

              No, just remove this line from your javascript:

              $('video').attr('preload', videopath);

              Maybe that helps!

              1 Reply Last reply
              0
              • S Offline
                S Offline
                silviu
                wrote on Feb 11, 2020, 5:51 PM last edited by
                #7

                @spontans said in Random Video Backgrounds on Homepage:

                Frontend.GlobalEvents.on("newpageshown", function(layoutObj, type, obj)

                hi/
                how will you approach this in 2020 ?
                i want to have the same , a script the randomly loads a video for the background page.
                the page i'm working on is http://telegraf.studio /
                thank you /

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mariusjopen
                  Global Moderator
                  wrote on Feb 12, 2020, 2:11 PM last edited by
                  #8

                  Dear @silviu
                  does the solution not work?

                  Best!

                  Marius

                  www.mariusjopen.world

                  S 1 Reply Last reply Feb 12, 2020, 7:45 PM
                  0
                  • M mariusjopen
                    Feb 12, 2020, 2:11 PM

                    Dear @silviu
                    does the solution not work?

                    Best!

                    Marius

                    S Offline
                    S Offline
                    silviu
                    wrote on Feb 12, 2020, 7:45 PM last edited by
                    #9

                    hey @mariusjopen ~ thanks for replying

                    i'm a total noob when it comes to web / wordpress environment , so please excuse if i'm missing something obvious .
                    so what i understand from @spontans code , applied to my project is this

                    if($("body").hasClass("slug-welcome")) {
                    var videosrc = Math.floor(Math.random() * 2) + 1;
                    var homeurl = 'http://telegraf.studio/wp-content/uploads/2020/02/'';
                    videopath = homeurl+videosrc+'.mp4';
                    $('video source').attr('src', videopath);
                    }

                    i've modified the slug-home2 on the first line to my page name : slug-welcome
                    the math.floor is modified from 6 to 2 , in my case i would like to have just 2 movies in the folder
                    the path is also changed to my media folder that contains the movies.

                    should i also modify $ to JQuery ?

                    where do i place this code ? i've read about custom css/html , but just adding this to custom html head dose not
                    work .

                    thanks

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      mariusjopen
                      Global Moderator
                      wrote on Feb 14, 2020, 11:26 AM last edited by
                      #10

                      Dear @silviu

                      should i also modify $ to JQuery ?
                      This is correct.

                      http://laytheme.com/documentation.html#custom-javascript

                      Try that!

                      Best!

                      Marius

                      www.mariusjopen.world

                      1 Reply Last reply
                      0
                      • K Offline
                        K Offline
                        Knudsn
                        wrote on Sep 8, 2020, 7:57 AM last edited by
                        #11

                        @silviu said in Random Video Backgrounds on Homepage:

                        hey @mariusjopen ~ thanks for replying

                        i'm a total noob when it comes to web / wordpress environment , so please excuse if i'm missing something obvious .
                        so what i understand from @spontans code , applied to my project is this

                        if($("body").hasClass("slug-welcome")) {
                        var videosrc = Math.floor(Math.random() * 2) + 1;
                        var homeurl = 'http://telegraf.studio/wp-content/uploads/2020/02/'';
                        videopath = homeurl+videosrc+'.mp4';
                        $('video source').attr('src', videopath);
                        }

                        i've modified the slug-home2 on the first line to my page name : slug-welcome
                        the math.floor is modified from 6 to 2 , in my case i would like to have just 2 movies in the folder
                        the path is also changed to my media folder that contains the movies.

                        should i also modify $ to JQuery ?

                        where do i place this code ? i've read about custom css/html , but just adding this to custom html head dose not
                        work .

                        thanks

                        Hey Silviu
                        Did you solve it?

                        I'm trying to get the above to work, but it seems like I'm missing something.

                        <script>
                        Frontend.GlobalEvents.on("newpageshown", function(layoutObj, type, obj) {
                        if(JQuery("body").hasClass("slug-home")) {
                        var videosrc = Math.floor(Math.random() * 3) + 1;
                        var homeurl = 'http://hidden.com/wp-content/uploads/'2020/09/';
                        videopath = homeurl+videosrc+'.mp4';
                        JQuery('video source').attr('src', videopath);
                        }
                        });
                        </script>

                        Best,
                        Christian

                        1 Reply Last reply
                        0
                        • RichardR Offline
                          RichardR Offline
                          Richard
                          Global Moderator
                          wrote on Sep 9, 2020, 2:59 PM last edited by
                          #12

                          Dear Christian @Knudsn

                          Use @silviu in order to make sure silviu was notified :)

                          Best of Luck
                          Richard

                          1 Reply Last reply
                          0
                          • K Offline
                            K Offline
                            Knudsn
                            wrote on Sep 10, 2020, 2:46 PM last edited by
                            #13

                            Thanks @Richard-Keith!
                            Fingers crossed

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            I also code custom websites or custom Lay features.
                            💿 Email me here: 💿
                            info@laytheme.com

                            Before you post:
                            1. When using a WordPress Cache plugin, disable it or clear your cache.
                            2. Update Lay Theme and all Lay Theme Addons
                            3. Disable all Plugins
                            4. Go to Lay Options → Custom CSS & HTML, click "Turn Off All Custom Code", click "Save Changes"

                            This often solves issues you might run into

                            When you post:
                            1. Post a link to where the problem is
                            2. Does the problem happen on Chrome, Firefox, Safari or iPhone or Android?
                            3. If the problem is difficult to explain, post screenshots / link to a video to explain it
                            Online Users
                            C
                            craigfeldspar
                            4 minutes ago
                            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