Created
March 28, 2012 00:51
-
-
Save l04m33/2222458 to your computer and use it in GitHub Desktop.
Funny script to make the 'img' tags flow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function() { | |
| var body = document.getElementsByTagName("body")[0]; | |
| var target_x = 10; | |
| var target_y = 10; | |
| var img_list = Array.prototype.slice.call(document.getElementsByTagName("img"), 0, 9); | |
| function img_iter(f) { | |
| for (var i in img_list) { | |
| if (img_list[i].style) { | |
| f(img_list[i]) | |
| } | |
| } | |
| } | |
| img_iter(function(img) { | |
| img.style.position = "fixed"; | |
| }); | |
| cb = function() { | |
| var prev_x = target_x; | |
| var prev_y = target_y; | |
| img_iter(function(img) { | |
| var c_rect = img.getBoundingClientRect(); | |
| var dx = prev_x - c_rect.left; | |
| var dy = prev_y - c_rect.top; | |
| prev_x = Math.floor(c_rect.left + dx * 0.2); | |
| prev_y = Math.floor(c_rect.top + dy * 0.2); | |
| img.style.left = prev_x + "px"; | |
| img.style.top = prev_y + "px"; | |
| }); | |
| } | |
| body.onmousemove = function(e) { | |
| target_x = e.clientX + 10; | |
| target_y = e.clientY + 10; | |
| }; | |
| return setInterval(cb, 30); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment