Created
April 10, 2009 19:28
-
-
Save charliepark/93248 to your computer and use it in GitHub Desktop.
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
/* | |
A way to set your z-index to dynamically update, based on the current time. | |
When you click on the object ('.element'), the javascript grabs the current time, | |
concatenates the hours, minutes, and seconds, and sets that number as the z-index for the object. | |
*/ | |
$('.element').mousedown(function(event) { | |
var time = new Date(); | |
var hours = time.getHours(); | |
if (hours.toString().length == 1) { hours = "0" + '' + hours } | |
var minutes = time.getMinutes(); | |
if (minutes.toString().length == 1) { minutes = "0" + '' + minutes } | |
var seconds = time.getSeconds(); | |
if (seconds.toString().length == 1) { seconds = '0' + '' + seconds } | |
var zindex = hours + '' + minutes + '' + seconds; | |
$(this).css('z-index',zindex); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I know this is 10 years old, but I am only posting in case someone else finds this as a solution for them - there's a couple of bugs here. getMinutes() is missing, 0's are dropped so it messes up the ordering, and this returns a string, not an integer. I propose this: -
var zindex = parseInt(time.getHours() + '' + ("0" + time.getMinutes()).slice(-2) + ("0" + time.getSeconds()).slice(-2));