Skip to content

Instantly share code, notes, and snippets.

@nickjshearer
Last active August 29, 2015 14:18
Show Gist options
  • Save nickjshearer/7cb7de5fae88e2c08d84 to your computer and use it in GitHub Desktop.
Save nickjshearer/7cb7de5fae88e2c08d84 to your computer and use it in GitHub Desktop.
Dial Up Images
// Dial-up modem image loading using canvas. Relive the glory days of the internet
//
// Usage:
// <canvas class="image-canvas" width="180" height="180" data-image="http://lorempixel.com/180/180/">
// <p>Image alt textc</p>
// </canvas>
//
window.onload = function() {
var elements = document.getElementsByClassName("image-canvas");
Array.prototype.forEach.call(elements, function(canvas) {
var context = canvas.getContext("2d");
var img = new Image();
var canvasHeight = canvas.offsetHeight;
img.src = canvas.getAttribute('data-image');
img.onload = function() {
var height = 0;
function animate(timestamp) {
height += Math.floor(Math.random()*10);
updateDelay = Math.floor(Math.random()*1000);
if (height > canvasHeight) {
height = canvasHeight;
}
context.drawImage(img, 0, 0, canvas.offsetWidth, height, 0, 0, canvas.offsetWidth, height);
if (height < canvasHeight) {
setTimeout(function(){window.requestAnimationFrame(animate)}, updateDelay);
}
}
window.requestAnimationFrame(animate);
};
});
};
@endocrimes
Copy link

Nice! - In codepen form: http://codepen.io/anon/pen/jERmNm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment