jQuery to Turn off or Turn on the lights while watching videos

Do you love watching videos online? Me too :D but what we needs to have to love more is that something like option of turning on or off lights around the page except the video. Just amazing that how it would be look and feel? Nice? Yeah ! Here we are going to talk about the same.


If you are running a video sharing website or you might sometimes need to embed videos in your blog posts. Let's do something different with it for your blog/website readers ! I am talking about a jQuery which let's users to turn off the lights while watching videos on your blog. which is made by Janko.

Related : How to Add Custom jQuery Lightbox to Blogspot blog


You can check how actually it works on the following demo blog - click the link that says "Turn off the lights" and the page will be darkened. To make the page elements active again, just click the "Turn on the lights" link:


How to add the "Turn off the Lights" Feature to Blogger/Blogspot

Go to blogger dashboard > Template > Edit HTML
Press CTRL + F to enable search box, then search for the following code:

</head>

Now, Copy and paste the following code just above the </head> tag.

    <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js' type='text/javascript'/>
    <script type='text/javascript'>
    //<![CDATA[
    $(document).ready(function(){
    $("#lightsoff").css("height", $(document).height()).hide();
    $(".lightSwitcher").click(function(){
    $("#lightsoff").toggle();
    if ($("#lightsoff").is(":hidden"))
    $(this).html("Turn off the lights").removeClass("turnedOff");
    else
    $(this).html("Turn on the lights").addClass("turnedOff");
    });
    });
    //]]>
    </script>

Note: if you already have one version of jquery in the template, please remove the line in red.

Now search for the following tag:

    ]]></b:skin>

Just above ]]></b:skin> add the following CSS:

    /* Turn off the lights
    ----------------------------------------------- */
    #lightsVideo {
    position:relative;
    z-index:102;
    }
    #switch {
    max-width:640px;
    text-align:left;
    position:relative;
    height:25px;
    display:block;
    margin: 25px 0 0 60px;
    }
    .lightSwitcher {
    position:absolute;
    z-index:101;
    background-image:url(http://3.bp.blogspot.com/-Vs5EJnjVScM/Um0Sq84fJtI/AAAAAAAAEeQ/PEu-OStZciA/s1600/lights-on.png);
    background-repeat:no-repeat;
    background-position:left;
    padding: 0 0 0 20px;
    outline:none;
    text-decoration:none;
    }
    .lightSwitcher:hover {text-decoration:underline;}
    .turnedOff {
    color:#ffff00 !important;
    background-image:url(http://3.bp.blogspot.com/-vKGxmBhYshA/Um0Sqwy_hNI/AAAAAAAAEeU/F0WKs6_WARM/s1600/lights-off.png);
    }
    #lightsoff {
    background:#000;
    opacity:0.9;
    filter:alpha(opacity=90);
    position:absolute;
    left:0;
    top:0;
    width:100%;
    z-index:100;
    }

Try to find this tag:

    </body>

Just above the </body> tag, add this HTML code:

    <div id='lightsoff'/>

Click the "Save Template" button and that's it!

Now, wherever you put your video, either a post or a HTML/Javascript gadget, use this code:

    <center>
    <div id="switch"><a class="lightSwitcher" href="javascript:void(0);">Turn off the lights</a></div>
    <div id="lightsVideo">
    ...Here goes the code of the video...
    </div>
    </center>

Add the code of your video instead of the blue text and "Save" or "Publish" your gadget / post. Now you can enjoy your videos with the lights off!

0 comments:

Post a Comment