Showing posts with label Coding. Show all posts
Showing posts with label Coding. Show all posts
Best Method to Embed YouTube Videos

Best Method to Embed YouTube Videos

You surprised to know that when you embed any YouTube video on your website using standard IFRAME tags, the webpage has to download 0.5 MB of extra resources (CSS, Javascript and images) for rendering the video player and 7-12 additional HTTP requests only adds to slowing down your pages indirectly. Files will also download even visitors on your website has choosen not to watch the video.

The default YouTube embed code isn't responsive. i.e. if people view your website on mobile phone, the video player would not resize itself.  The Standard embed video is making your web page heavy and increase overall page loading time due to visitors browser will need to make multiple HTTP requests to render the video player.

Load YouTube Video Player On-Demand

Google Plus uses a technique to reduce the time taken by web page to initially load the YouTube video player. Google Plus displays the thumbnails images of a YouTube video and a "Play" icon is placed over the video. When the user hits the play button, the video thumbnail is replaced with the standard YouTube video player with autoplay set to 1 so it plays the video instantly. 

The standard embed code for YouTube looks something like this. You can specify the height of the player (in pixels), the width and the unique ID of the YouTube video.

<iframe width="320" height="180"
     src="http://www.youtube.com/embed/LcIytqkbdlo">
</iframe>

Embed YouTube Videos Responsively

Copy and Paste the following snippet anywhere in your web page where you would like the video to appear. Replace the VIDEOID with the actual ID of the YouTube video.

<div class="youtube-container">
   <div class="youtube-player" data-id="VIDEOID"></div>
</div>

If you want to embed multiple Youtube video on same web page just copy and paste the given code multiple time and replace the VIDEOID with different video.

The JavaScript

This code will scan your pages for embedded YouTube videos. Also add thumbnail image and oneclick event listener.

<script>
(function() {
    var v = document.getElementsByClassName("youtube-player");
    for (var n = 0; n < v.length; n++) {
        var p = document.createElement("div");
        p.innerHTML = labnolThumb(v[n].dataset.id);
        p.onclick = labnolIframe;
        v[n].appendChild(p);
    }
})();

function labnolThumb(id) {
    return '<img class="youtube-thumb" src="//i.ytimg.com/vi/' + id + '/hqdefault.jpg"><div class="play-button"></div>';
}

function labnolIframe() {
    var iframe = document.createElement("iframe");
    iframe.setAttribute("src", "//www.youtube.com/embed/" + this.parentNode.dataset.id + "?autoplay=1&autohide=2&border=0&wmode=opaque&enablejsapi=1&controls=0&showinfo=0");
    iframe.setAttribute("frameborder", "0");
    iframe.setAttribute("id", "youtube-iframe");
    this.parentNode.replaceChild(iframe, this);
}
</script>

The CSS

Open the CSS file of your website and paste the following snippet. If you don’t have a separate CSS file, you can also place it before the closing head tag of your web template.

<style>
.youtube-container { display: block; margin: 20px auto; width: 100%; max-width: 600px; }
.youtube-player { display: block; width: 100%; /* assuming that the video has a 16:9 ratio */ padding-bottom: 56.25%; overflow: hidden; position: relative; width: 100%; height: 100%; cursor: hand; cursor: pointer; display: block; }
img.youtube-thumb { bottom: 0; display: block; left: 0; margin: auto; max-width: 100%; width: 100%; position: absolute; right: 0; top: 0; height: auto }
div.play-button { height: 72px; width: 72px; left: 50%; top: 50%; margin-left: -36px; margin-top: -36px; position: absolute; background: url("http://i.imgur.com/TxzC70f.png") no-repeat; }
#youtube-iframe { width: 100%; height: 100%; position: absolute; top: 0; left: 0; }
</style>

This method will reduce the size of your web pages by 300-400 KB and making your site mobile friendly.

How to Remove Labels From Blogger Post

In google blogger, Categories are named Labels whereas in wordpress it called categoreis. Managing Labels in goole blogger isn't as straightforward as in wordpress.

when blogger apply a new template, many blogger find Labels below posts unnecessary, as these labels are already in thier blog's sidebar. so today i will show you how to remove them manually from the Templates's HTML. 


To hide labels from the blogger post footer or below post title, we could simply uncheck the "Labels" option, however this setting might not work properly in some custom templates. So we have to remove the code from our template.


Here are some steps to follow carefully.


Hide Labels Using CSS Code

Step 1.  Log in to your Blogger account > Click On Template Tab > Hit the 'Edit HTML' button




Step 2. Now search for this code by using CTRL + F

</head>


Step 3.  Just above the </head> tag, put the following code

<style>
.post-labels {
display: none;
}
</style>


Step 4.  Click the 'Save Template' button to save the changes and view your blog. its done

Best website to Learn Coding

Many of us want to learn coding online but we don't find good websites which provide flexibility in learn to coding.

These days many of us want to learn code and if you can teach yourself how to write code, you can compete with world and think more algorithmically thus can tackle problems more efficiently. 



Don't just download the latest app, help redesing it. Don't just play on your phone, program it. - Obama


If you learn basic of coding, then you will be able to do the many things like Automate Tasks, program your Excel Sheets, improve workflows, extract data from websites, communicate with developers and many more.

Here i will show you best websites list which offer courses in a variety of Programming language for free. I also added the list of companion ebooks that will give you best understanding of the language and its totally free.




Online Courses & Screencasts
Programming Books (Free)
JavaScript
HTML & CSS
jQuery
Python
Ruby & Ruby on Rails
PHP
Google Apps Script
WordPress
Linux & Shell Scripting
Node.js
Angular JS
Git (version control)
Objective-C (iOS & Mac)
Chrome Dev Tools
Go Language
Java
Android App Development
D3 (data visualization)
SQL (Databases)
Everything Else


For kids wants to learn the coding

1. Tynker (Android/iOS)
2. Hopscotch app for iPad

you should download it and learn the basic of programming through games and puzzles.

3. Scratch, an MIT project that allows kids to program their own stories and games visually.
4. Blockly and Alice

Last five years Google Trends shows the relatively search popularity of Variou programming language. JavaScript maintain its top position.