Skip to content

Instantly share code, notes, and snippets.

@i7an
Forked from anonymous/slider.js
Last active January 16, 2018 19:30
Show Gist options
  • Save i7an/338632aded0931a1334854b3cf13a4f3 to your computer and use it in GitHub Desktop.
Save i7an/338632aded0931a1334854b3cf13a4f3 to your computer and use it in GitHub Desktop.
(function () {
var mrg = 0;
var id = 'slider';
var klass = 'slider';
var interval = 2000;
var mainEl = document.getElementById(id)
if (!mainEl) {
console.error('Failed to find El#' + id);
return;
}
var insideEl = mainEl.getElementsByClassName(klass)[0]
if (!insideEl) {
console.error('Failed to find El.' + klass + ' inside El#' + id);
return;
}
setInterval(function() {
var marginPx = (mrg % 5) * 1000
insideEl.style = 'margin-left: -' + marginPx + 'px'
mrg++;
}, interval);
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment