| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- $(function () {
- 'use strict';
- var container = $('container');
- var contentContainer0 = $('#content0');
- var contentContainer1 = $('#content1');
- var curContentContainer = contentContainer0;
- var nextContentContainer = contentContainer1;
- var content = [];
- function preload(imageUrl, callback) {
- var img = new Image();
- img.onload = function () {
- callback();
- };
- img.src = imageUrl;
- }
- function random(values) {
- return values[Number.parseInt(Math.random()*values.length)];
- }
- function showNext() {
- var img = random(content);
- preload(img, function () {
- nextContentContainer.css('background-image', 'url("' + img + '")');
- nextContentContainer.css('background-repeat', random(['no-repeat', 'space', 'repeat']));
- nextContentContainer.css('background-size', random(['cover', 'contain', 'unset', '50%', '120%', '30%']));
- if (random(['fade', 'slide']) === 'fade') {
- curContentContainer.fadeOut();
- nextContentContainer.fadeIn();
- } else {
- curContentContainer.slideToggle();
- nextContentContainer.slideToggle();
- }
- var tmp = nextContentContainer;
- nextContentContainer = curContentContainer;
- curContentContainer = tmp;
- setTimeout(showNext, 3000);
- });
- }
- $.get('/content.json', function (data) {
- content = data.content.map(function (img) { return img.replace('http://', 'https://'); }).map(function (img) { return img.replace('_75sq', '_500'); });
- showNext();
- });
- });
|