Skip to content

Instantly share code, notes, and snippets.

@daveschumaker
Last active August 29, 2015 14:10
Show Gist options
  • Save daveschumaker/6dac18e129fb9152815e to your computer and use it in GitHub Desktop.
Save daveschumaker/6dac18e129fb9152815e to your computer and use it in GitHub Desktop.
GIFtv - index.php
<?php
/*
¡GIFtv!
*/
include('image_update.php');
?>
<html>
<head>
<title>GIFtv</title>
<style>
body {
background: url(<?php getImage($images); ?>) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
</style>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type = "text/javascript">
function displayNextImage() {
var body = document.getElementsByTagName('body')[0];
var i = Math.floor(<?php echo count($images); ?>*Math.random());
body.style.backgroundImage = 'url(' + images[i] + ')';
}
function startTimer() {
setInterval(displayNextImage, 5000);
}
var images = [];
<?php buildImages($images); ?>
console.log("HELLO! Initial image array load!");
console.log(images);
console.log("END Initial image array load.");
</script>
</head>
<body onload = "startTimer()">
<div class="container">
</div>
<script>
setInterval(function() {
$.get('image_update.php?m=update', function(data) {
$.get("images.txt", function(data) {
var images = data.split(',');
console.log(images);
// This is where things are going wrong. console.log(images) returns the proper data
// and shows I've added images to the folder. But it doesn't update the images array that
// I defined way up on line 36.
});
});
}, 5000);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment