2011-08-24 6 views
-4

누구든지 부동 발룬을 위해 어떤 자바 스크립트를 사용하고 있는지 조사 할 수 있습니까? - http://themeforest.net/bundles/birthday주어진 링크에서 어떤 자바 스크립트를 사용하고 있습니까?

나는 방화 모자를 한동안 찾고 있었지만, 맞지는 않았다. 감사! ... 다른 반복 코딩 공포가 사용되는 경우

+1

정확한 문제는 무엇입니까? – Einacio

+1

http://themeforest.net/bundles/javascripts/birthday_running.js – cwallenpoole

+0

그들은 jQuery (http://jquery.com/) 및 일부 맞춤 메소드를 사용하여 풍선을 애니메이션합니다. –

답변

3

http://themeforest.net/bundles/javascripts/birthday_running.js

그리고 여기가 끔찍하게 무서운입니다.

$(".balloon").each(function() { 
     var $this = $(this), 
      width = $this.width(), 
      height = $this.height(), 
      rand = Math.random(), 
      bgPosX, 
      bgPosY = rand * (height), 
      bgImg, 
      animStep = 1 + (rand * 3), 
      moveBalloon, 
      animLoop; 

     if ($this.is(".b1")) { 
      bgPosX = Math.floor((width/2)) - 620; 
      bgImg = 1; 
     } else if ($this.is(".b2")) { 
      bgPosX = Math.floor((width/2)) - 540; 
      bgImg = 2; 
     } else if ($this.is(".b3")) { 
      bgPosX = Math.floor((width/2)) - 590; 
      bgImg = 3; 
     } else if ($this.is(".b4")) { 
      bgPosX = Math.floor((width/2)) - 590; 
      bgImg = 4; 
     } else if ($this.is(".b5")) { 
      bgPosX = Math.floor((width/2)) + 470; 
      bgImg = 2; 
     } else if ($this.is(".b6")) { 
      bgPosX = Math.floor((width/2)) + 450; 
      bgImg = 4; 
     } else if ($this.is(".b7")) { 
      bgPosX = Math.floor((width/2)) + 510; 
      bgImg = 1; 
     } else if ($this.is(".b8")) { 
      bgPosX = Math.floor((width/2)) + 560; 
      bgImg = 3; 
     } 

     $this.css({ 
      "background-position": bgPosX + "px " + bgPosY + "px", 
      "background-image": "url(/images/bundles/birthday/balloon" + bgImg + ".png)" 
     }); 

     moveBalloon = function() { 
      if (bgPosY < -204) { 
       bgPosY = $this.height(); 
      } 
      bgPosY -= animStep; 
      $this.css("background-position", bgPosX + "px " + bgPosY + "px");  
     }; 

     animLoop = function() { 
      moveBalloon(); 
      window.requestAnimFrame(animLoop); 
     }; 

     animLoop(); 

     $this.addClass("balloon"); 
    }); 
+0

그 Math.floor()는 어떨까요? 매번 호출되는 동일한 작업 gettin ??? 고약한 –

관련 문제