window.onload = function () {
reset();
initialize();
var interval = false;
var cloudInterval = false;
window.setTimeout(function () {
if (navigator.userAgent.search("Safari") >= 0 & navigator.userAgent.search("Chrome") < 0) {
alert("There is a bug with this animation is Safari (mobile and desktop) which makes the sun flicker when it rotates. If you know how to fix this bug, please email me at [email protected] or [email protected]");
}
}, 5000);
function initialize() {
//add inline rotation for more neatly written code...
var rays = document.getElementsByClassName('ray');
for (var i = 0; i != rays.length; i++) {
var rotation = rays[i].getAttribute('data-rotation');
//add native transform support
rays[i].style.oTransform = 'rotate(' + rotation + 'deg)';
rays[i].style.msTransform = 'rotate(' + rotation + 'deg)';
rays[i].style.webkitTransform = 'rotate(' + rotation + 'deg)';
rays[i].style.mozTransform = 'rotate(' + rotation + 'deg)';
rays[i].style.transform = 'rotate(' + rotation + 'deg)';
rays[i].style.width = '6px';
}
//add control for the interval
interval = window.setInterval(function () {
var randomRay = rays[Math.floor(Math.random() * rays.length)];
if (parseInt(randomRay.style.width) === 6) {
randomRay.style.width = '3px';
} else {
randomRay.style.width = '6px';
}
}, 100);
}
function reset() {
document.getElementById('cloudContainer').innerHTML = '';
var numberOfClouds = Math.floor(window.innerWidth / 200);
var positions = [40, 55, 70, 85, 100];
for (var i = 0; i != numberOfClouds; i++) {
var cloud = document.createElement('div');
cloud.className = 'cloud';
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.