How to turn a video into a floating window in WordPress and Blogger ?
In this article we are going to see how to easily turn a video into a floating window in WordPress and Blogger. This will be embedded in the lower corner of the screen when the user scrolls through the page. He can then continue reading or browse a page of your website while continuing to watch the video. |
This feature will not be automatic for all videos. You will be able to activate it or not for a specific video. In addition, the latter will be fully responsive and will adapt to all screens (smartphone, tablet).e
We will add two codes in your WordPress or Blogger theme: a JavaScript code (JQuery) and a CSS code.
To facilitate the integration of the codes in the files of your WordPress theme, we will use a plugin that allows you to incorporate JavaScript and CSS codes without having to modify the files in the theme editor. That said, you are free to insert them directly without a plugin if you have the necessary technical knowledge.
The plugin we will use in this tutorial is called "Insert Headers and Footers".
Note: You can choose any plugin that allows you to insert JavaScript and CSS codes into WordPress theme files.
The first part will be devoted to the installation of the floating video in Wordpress then in the second in the Blogger platform and in the last part of this tutorial, we will discuss the activation method which is common to both platforms.
Prerequisites before installing the Floating Video Functionality
The first step is to make sure that the jQuery library is enabled in your theme.
In WordPress
View the source code of your website in a web browser, then search for "jquery" in your search bar.
Regardless of the version, your jQuery code will look like this:
<script type = 'text / javascript' src = 'https: //votre-site-web.com /wp-includes/js/jquery/jquery.js?ver=1.12.4-wp'> </script> < script type = 'text / javascript' src = 'https: //votre-site-web.com /wp-includes/js/jquery/jquery-migrate.min.js?ver=1.4.1'> </script>
In Blogger
To verify that the jQuery library is properly installed in your Blogger theme, you will need to access the HTML code.
Reminder : Before starting any modification of the HTML code of your theme, I strongly advise you to save a copy of your theme.
You will probably find code that looks like this:
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"> </script>
If you can't find any jQuery code in your theme, add the following code above the </head> tag.<script src = "https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"> </script>
JQuery version 3.1.1
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"> </script>
JQuery version 3.5.1
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"> </script>
Note: Your theme must contain only one version of the jQuery library to avoid any malfunction or conflicts between the different versions.
Add a video in a floating window in WordPress
Add CSS Properties
<style type = 'text / css'> .iframevid {position: absolute; left: 0; right: 0; top: 0; bottom: 0; float: left; overflow: hidden; margin-right: 12px; animation: littleShine .85s linear infinite; background: # f5f5f5 linear-gradient (to right, rgba (255,255,255,0) 5%, rgba (255,255,255, .75) 20%, rgba (255,255,255,0) 30%); background-size: 800px 100px} .containervid {text-align: center} .floatvid iframe {max-width: 100%; max-height: 100%} .floatvid.fly {padding: 0; position: fixed; bottom: 20px; right: 20px; box-shadow: 0 8px 10px -5px rgba (0,0,0,0.15); - webkit-transform: translateY (100%); transform: translateY (100%); width: 260px; height: 145px; -webkit- animation: fade-in-up .25s ease forwards; animation: fade-in-up .25s ease forwards; z-index: 99} .youtubevid {text-align: center; margin: auto; width: 100%} .responsivevid {position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden} .responsivevid iframe {position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: 0} @media screen and (max-width: 640px) {.floatvid.fly {bottom: 10px; right: 10px; width: 160px ; height: 85px} .responsivevid {padding-bottom: 54%}} @keyframes fade-in-up {0% {opacity: 0} 100% {- webkit-transform: translateY (0); transform: translateY (0) ; opacity: 1}} @keyframes littleShine {0% {background-position: -400px 0} 100% {background-position: 400px 0}} </style>
Insert JavaScript Code
<script type = 'text / javascript'> jQuery (document) .ready (function ($) {var $ window = $ (window), $ floatvideoWrap = $ (". containervid"), $ floatvid = $ (". floatvid "), floatvideoHeight = $ floatvid.outerHeight (); $ window.on (" scroll ", function () {$ window.scrollTop ()> floatvideoHeight + $ floatvideoWrap.offset (). top? ($ floatvideoWrap.height (floatvideoHeight) , $ floatvid.addClass ("fly")): ($ floatvideoWrap.height ("auto"), $ floatvid.removeClass ("fly"))}), setTimeout (function () {$ (". youtubevid-frame" ) .each (function () {$ (this) .replaceWith ('<iframe class = "youtubevid-frame iframevid" src = "' + $ (this) .data (" src ") + '" allowfullscreen = "allowfullscreen" height = "281" width = "500"> </iframe> ')})}, 5e3);}); </script>
Add a video in a floating window in Blogger
Add CSS Code
Step 2. Look for the beacon </head>
Step 3. Insert the following CSS code just above the tag </head>
<style type='text/css'>
.iframevid{position:absolute;left:0;right:0;top:0;bottom:0;float:left;overflow:hidden;margin-right:12px;animation:littleShine .85s linear infinite;background:#f5f5f5 linear-gradient(to right,rgba(255,255,255,0) 5%,rgba(255,255,255,.75) 20%,rgba(255,255,255,0) 30%);background-size:800px 100px}
.containervid{text-align:center}
.floatvid iframe{max-width:100%;max-height:100%}
.floatvid.fly{padding:0;position:fixed;bottom:20px;right:20px;box-shadow:0 8px 10px -5px rgba(0,0,0,0.15);-webkit-transform:translateY(100%);transform:translateY(100%);width:260px;height:145px;-webkit-animation:fade-in-up .25s ease forwards;animation:fade-in-up .25s ease forwards;z-index:99}
.youtubevid{text-align:center;margin:auto;width:100%}
.responsivevid{position:relative;padding-bottom:56.25%;height:0;overflow:hidden}
.responsivevid iframe{position:absolute;top:0;left:0;width:100%;height:100%;border:0}
@media screen and (max-width:640px) {
.floatvid.fly{bottom:10px;right:10px;width:160px;height:85px}
.responsivevid{padding-bottom:54%}
}
@keyframes fade-in-up {
0%{opacity:0}
100%{-webkit-transform:translateY(0);transform:translateY(0);opacity:1}
}
@keyframes littleShine {
0%{background-position:-400px 0}
100%{background-position:400px 0}
}
</style>
Insert JavaScript Code
- Look for the tag </body> in the HTML code of your theme
- Add the following code above the tag </body>.
<script type='text/javascript'>
//<![CDATA[
var $window=$(window),$floatvideoWrap=$(".containervid"),$floatvid=$(".floatvid"),floatvideoHeight=$floatvid.outerHeight();$window.on("scroll",function(){$window.scrollTop()>floatvideoHeight+$floatvideoWrap.offset().top?($floatvideoWrap.height(floatvideoHeight),$floatvid.addClass("fly")):($floatvideoWrap.height("auto"),$floatvid.removeClass("fly"))}),setTimeout(function(){$(".youtubevid-frame").each(function(){$(this).replaceWith('<iframe class="youtubevid-frame iframevid" src="'+$(this).data("src")+'" allowfullscreen="allowfullscreen" height="281" width="500"></iframe>')})},5e3);
//]]>
</script>
Enable the Floating video feature in WordPress and Blogger (Common Activation Method)
Turn a YouTube video into a floating window
- Below your YouTube video, click on the "Share" menu
- Then click on the "Integrate" button
<iframe width="560" height="315" src="https://www.youtube.com/embed/ tOFjX6R2rEU" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
We will only need the URL of the video.Insert the iFrame link in the HTML code for activating the Floating Window
<div class="containervid">
<div class="floatvid">
<div class="youtubevid">
<div class="responsivevid">
<div class="youtubevid-frame iframevid" data-src="//www.youtube.com/embed/tOFjX6R2rEU"></div>
</div>
</div>
</div>
</div>
Replace the link in the code with your own. src="//www.youtube.com/embed/tOFjX6R2rEU">Enable the feature for a video hosted on Google Drive
<iframe src="https://drive.google.com/file/d/1TujYp5npvm7UwCjH2-bYBVwjbTsTPSQI/preview" width="640" height="480"></iframe>
As with YouTube videos, just insert the URL address in the HTML code below:<div class="containervid">
<div class="floatvid">
<div class="youtubevid">
<div class="responsivevid">
<div class="youtubevid-frame iframevid" data-src='//drive.google.com/file/d/1TujYp5npvm7UwCjH2-bYBVwjbTsTPSQI/preview '></div>
</div>
</div>
</div>
</div>
Enable the feature for a video hosted in platforms like Vimeo, Dailymotion, etc.
<div class="containervid">
<div class="floatvid">
<iframe src="https://player.vimeo.com/video/27129110" width="640" height="360" frameborder="0" allow="autoplay; fullscreen" allowfullscreen></iframe>
</div>
</div>
1 comment