Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
3,994
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. $(document).ready(function(e) {
  2. var sw = 0;
  3. if (typeof(window.innerWidth) == 'number') {
  4. sw = window.innerWidth;
  5. } else if (document.documentElement && document.documentElement.clientWidth) {
  6. sw = document.documentElement.clientWidth;
  7.  
  8. } else if (document.body && document.body.clientWidth) {
  9. sw = document.body.clientWidth;
  10. };
  11.  
  12. function hoaroi_free() {
  13. setTimeout(function() {
  14. window.requestAnimationFrame(hoaroi_free);
  15. }, 1000);
  16. var size = (Math.floor(Math.random() * (30 - 10)) + 10);
  17. var xPosition = (Math.floor(Math.random() * (sw - size-2)) + (size+2));
  18. var yPosition = 0;
  19.  
  20. var l = document.createElement("DIV");
  21. l.style.width = size + "px";
  22. l.style.height = size + "px";
  23. l.style.backgroundImage = "url( https://lh3.googleusercontent.com/-xXs4wti-JDo/Vqk2sWmawnI/AAAAAAAA9TM/nkwuMRATKM4/s128-Ic42/hoaroi-VIETDESIGNER.NET.png)";
  24. var bg_pos = (Math.floor(Math.random() * 4));
  25. l.style.backgroundPosition = "0px -"+(size*bg_pos)+"px";
  26. l.style.backgroundSize = size + "px "+4*size+"px"
  27. l.style.position = "absolute";
  28. l.style.left = (xPosition) + "px";
  29. l.style.top = (yPosition + 10) + "px";
  30. l.style.zIndex = 9999;
  31. l.style.display = 'none';
  32. document.body.appendChild(l);
  33. $(l).fadeIn(500);
  34. var stop = false;
  35. var hoaroi = function() {
  36. if (!stop) {
  37. setTimeout(function() {
  38. window.requestAnimationFrame(hoaroi);
  39. }, 20);
  40. l.style.top = (parseInt($(l).css('top'), 10) + 1) + "px";
  41. if ((parseInt($(l).css('top'), 10)) % 10 == 0) {
  42. if (Math.random() < 0.5) {
  43. l.style.left = (parseInt($(l).css('left'), 10) + 1) + "px";
  44. } else {
  45. l.style.left = (parseInt($(l).css('left'), 10) - 1) + "px";
  46. }
  47. }
  48. }
  49. }
  50. window.requestAnimationFrame(hoaroi);
  51. setTimeout(function() {
  52. $(l).fadeOut((Math.floor(Math.random() * (6000 - 2500)) + 2500), function() {
  53. $(l).remove();
  54. stop = true;
  55. });
  56. }, (Math.floor(Math.random() * (15000 - 5000)) + 5000));
  57. }
  58. window.requestAnimationFrame(hoaroi_free);
  59.  
  60.  
  61. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement