Created
May 12, 2011 13:06
-
-
Save leylaso/968450 to your computer and use it in GitHub Desktop.
Javascript function to show an element only during a specific time, depends on jQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Initialize some variables - we will use GMT times | |
var checkDate = new Date(); | |
var offTheHourStarts = 21; | |
var offTheHourEnds = 22; | |
// Adjust for Daylight savings | |
if ((checkDate.getMonth() < 2 && checkDate.getMonth() > 10) || (checkDate.getMonth() == 2 && checkDate.getDate()-checkDate.getDay() > 7 ) || (checkDate.getMonth() == 10 && checkDate.getDate()-checkDate.getDay() > 1)) { | |
offTheHourStarts--; | |
offTheHourEnds--; | |
} | |
/** | |
* Create a function to display the ckut stream if we are in the right hours | |
*/ | |
function showCkutStream = function (context) { | |
var timeDate = new Date(); | |
if (offTheHourStarts < timeDate.getHours()+timeDate.getTimezoneOffset()/60 > offTheHourEnds) { | |
$('#ckutStream').show(); | |
} | |
else { | |
$('#ckutStream').hide(); | |
} | |
}; | |
/** | |
* Run the display function every minute | |
*/ | |
$(document).ready( function() { | |
$(this).setInterval("showCkutStream()", 60000); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can this be used to showcase a certain video embed code at a certain hour - i.e 7pm EST? - should one replace '#ckutStream' - with such code?