Created
May 19, 2017 14:08
-
-
Save victoriadrake/79247ed3c9b3a4e03a3190097b4d2b39 to your computer and use it in GitHub Desktop.
Bit of jQuery that changes a message when the page loads, dpending on the current hour.
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
// changes based on current time | |
var time = new Date().getMinutes(); | |
// sets the time to every ten minutes | |
var index = Math.floor(time/10); | |
var json = { | |
0:"Clever message zero.", | |
1:"Clever message one.", | |
2:"Clever message two.", | |
3:"Clever message three.", | |
4:"Clever message four.", | |
5:"Clever message five." | |
}; | |
function getTagline(json, index) { | |
//gets message that corresponds to time index | |
$('#tagline').html(json[index]); | |
} | |
$(document).ready(function() { | |
getTagline(json, index); | |
//you can click on the field to advance and loop through messages | |
$('#tagline').on('click', function(){ | |
if (index == 5) {index = -1;} | |
getTagline(json, index+=1); | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment