Skip to content

Instantly share code, notes, and snippets.

@peterschmiz
Created July 10, 2017 15:40
Show Gist options
  • Save peterschmiz/054beb069cd981e42389999a5b1e5de0 to your computer and use it in GitHub Desktop.
Save peterschmiz/054beb069cd981e42389999a5b1e5de0 to your computer and use it in GitHub Desktop.
// source https://jsbin.com
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
(function() {
var light = document.querySelector('.f1-lights .light-strip:last-child');
var wentOn = false;
var event = new MouseEvent('mousedown', {
'view': window,
'bubbles': true,
'cancelable': true
});
function init() {
window.requestAnimationFrame(loop);
}
function loop() {
var isItOn = light.classList.contains('on');
var doLoop = true;
if (isItOn && wentOn === false) {
wentOn = true;
} else if (isItOn === false && wentOn) {
doLoop = false;
document.body.dispatchEvent(event);
}
if (doLoop) {
window.requestAnimationFrame(loop);
}
}
init();
}());
</script>
<script id="jsbin-source-javascript" type="text/javascript">(function() {
var light = document.querySelector('.f1-lights .light-strip:last-child');
var wentOn = false;
var event = new MouseEvent('mousedown', {
'view': window,
'bubbles': true,
'cancelable': true
});
function init() {
window.requestAnimationFrame(loop);
}
function loop() {
var isItOn = light.classList.contains('on');
var doLoop = true;
if (isItOn && wentOn === false) {
wentOn = true;
} else if (isItOn === false && wentOn) {
doLoop = false;
document.body.dispatchEvent(event);
}
if (doLoop) {
window.requestAnimationFrame(loop);
}
}
init();
}());
</script></body>
</html>
(function() {
var light = document.querySelector('.f1-lights .light-strip:last-child');
var wentOn = false;
var event = new MouseEvent('mousedown', {
'view': window,
'bubbles': true,
'cancelable': true
});
function init() {
window.requestAnimationFrame(loop);
}
function loop() {
var isItOn = light.classList.contains('on');
var doLoop = true;
if (isItOn && wentOn === false) {
wentOn = true;
} else if (isItOn === false && wentOn) {
doLoop = false;
document.body.dispatchEvent(event);
}
if (doLoop) {
window.requestAnimationFrame(loop);
}
}
init();
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment