Skip to content

Instantly share code, notes, and snippets.

@israeljrs
Last active July 19, 2016 18:18
Show Gist options
  • Save israeljrs/eeb0eba7662dc875e6d833b603390495 to your computer and use it in GitHub Desktop.
Save israeljrs/eeb0eba7662dc875e6d833b603390495 to your computer and use it in GitHub Desktop.
//Fade an element out and then remove it
var s = document.getElementById('thing').style;
s.opacity = 1;
(function fade(){(s.opacity-=.1)<0?s.display="none":setTimeout(fade,40)})();
//Make an AJAX call
var r = new XMLHttpRequest();
r.open("POST", "path/to/api", true);
r.onreadystatechange = function () {
if (r.readyState != 4 || r.status != 200) return;
alert("Success: " + r.responseText);
};
r.send("banana=yellow");
// add class to button with vanilla.js.
// using the animate.css.
document.querySelector('button').addEventListener('click',function(e){
e.preventDefault();
document.querySelector('div').classList.add('dance');
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment