[JavaScript] var $window = $(window), gardenCtx, gard →→→→→进入此内容的聊天室

来自 , 2019-04-23, 写在 JavaScript, 查看 101 次.
URL http://www.code666.cn/view/cff02a74
  1. // variables  
  2.  
  3. var $window = $(window), gardenCtx, gardenCanvas, $garden, garden;  
  4.  
  5. var clientWidth = $(window).width();  
  6.  
  7. var clientHeight = $(window).height();  
  8.  
  9.    
  10.  
  11. $(function () {  
  12.  
  13.     // setup garden  
  14.  
  15.     $loveHeart = $("#loveHeart");  
  16.  
  17.     var offsetX = $loveHeart.width() / 2;  
  18.  
  19.     var offsetY = $loveHeart.height() / 2 - 55;  
  20.  
  21.     $garden = $("#garden");  
  22.  
  23.     gardenCanvas = $garden[0];  
  24.  
  25.     gardenCanvas.width = $("#loveHeart").width();  
  26.  
  27.     gardenCanvas.height = $("#loveHeart").height()  
  28.  
  29.     gardenCtx = gardenCanvas.getContext("2d");  
  30.  
  31.     gardenCtx.globalCompositeOperation = "lighter";  
  32.  
  33.     garden = new Garden(gardenCtx, gardenCanvas);  
  34.  
  35.        
  36.  
  37.     $("#content").css("width", $loveHeart.width() + $("#code").width());  
  38.  
  39.     $("#content").css("height", Math.max($loveHeart.height(), $("#code").height()));  
  40.  
  41.     $("#content").css("margin-top", Math.max(($window.height() - $("#content").height()) / 2, 10));  
  42.  
  43.     $("#content").css("margin-left", Math.max(($window.width() - $("#content").width()) / 2, 10));  
  44.  
  45.    
  46.  
  47.     // renderLoop  
  48.  
  49.     setInterval(function () {  
  50.  
  51.         garden.render();  
  52.  
  53.     }, Garden.options.growSpeed);  
  54.  
  55. });  
  56.  
  57.    
  58.  
  59. $(window).resize(function() {  
  60.  
  61.     var newWidth = $(window).width();  
  62.  
  63.     var newHeight = $(window).height();  
  64.  
  65.     if (newWidth != clientWidth && newHeight != clientHeight) {  
  66.  
  67.         location.replace(location);  
  68.  
  69.     }  
  70.  
  71. });  
  72.  
  73.    
  74.  
  75. function getHeartPoint(angle) {  
  76.  
  77.     var t = angle / Math.PI;  
  78.  
  79.     var x = 19.5 * (16 * Math.pow(Math.sin(t), 3));  
  80.  
  81.     var y = - 20 * (13 * Math.cos(t) - 5 * Math.cos(2 * t) - 2 * Math.cos(3 * t) - Math.cos(4 * t));  
  82.  
  83.     return new Array(offsetX + x, offsetY + y);  
  84.  
  85. }  
  86.  
  87.    
  88.  
  89. function startHeartAnimation() {  
  90.  
  91.     var interval = 50;  
  92.  
  93.     var angle = 10;  
  94.  
  95.     var heart = new Array();  
  96.  
  97.     var animationTimer = setInterval(function () {  
  98.  
  99.         var bloom = getHeartPoint(angle);  
  100.  
  101.         var draw = true;  
  102.  
  103.         for (var i = 0; i < heart.length; i++) {  
  104.  
  105.             var p = heart[i];  
  106.  
  107.             var distance = Math.sqrt(Math.pow(p[0] - bloom[0], 2) + Math.pow(p[1] - bloom[1], 2));  
  108.  
  109.             if (distance < Garden.options.bloomRadius.max * 1.3) {  
  110.  
  111.                 draw = false;  
  112.  
  113.                 break;  
  114.  
  115.             }  
  116.  
  117.         }  
  118.  
  119.         if (draw) {  
  120.  
  121.             heart.push(bloom);  
  122.  
  123.             garden.createRandomBloom(bloom[0], bloom[1]);  
  124.  
  125.         }  
  126.  
  127.         if (angle >= 30) {  
  128.  
  129.             clearInterval(animationTimer);  
  130.  
  131.             showMessages();  
  132.  
  133.         } else {  
  134.  
  135.             angle += 0.2;  
  136.  
  137.         }  
  138.  
  139.     }, interval);  
  140.  
  141. }  
  142.  
  143.    
  144.  
  145. (function($) {  
  146.  
  147.     $.fn.typewriter = function() {  
  148.  
  149.         this.each(function() {  
  150.  
  151.             var $ele = $(this), str = $ele.html(), progress = 0;  
  152.  
  153.             $ele.html('');  
  154.  
  155.             var timer = setInterval(function() {  
  156.  
  157.                 var current = str.substr(progress, 1);  
  158.  
  159.                 if (current == '<') {  
  160.  
  161.                     progress = str.indexOf('>', progress) + 1;  
  162.  
  163.                 } else {  
  164.  
  165.                     progress++;  
  166.  
  167.                 }  
  168.  
  169.                 $ele.html(str.substring(0, progress) + (progress & 1 ? '_' : ''));  
  170.  
  171.                 if (progress >= str.length) {  
  172.  
  173.                     clearInterval(timer);  
  174.  
  175.                 }  
  176.  
  177.             }, 75);  
  178.  
  179.         });  
  180.  
  181.         return this;  
  182.  
  183.     };  
  184.  
  185. })(jQuery);  
  186.  
  187.    
  188.  
  189. function timeElapse(date){  
  190.  
  191.     var current = Date();  
  192.  
  193.     var seconds = (Date.parse(current) - Date.parse(date)) / 1000;  
  194.  
  195.     var days = Math.floor(seconds / (3600 * 24));  
  196.  
  197.     seconds = seconds % (3600 * 24);  
  198.  
  199.     var hours = Math.floor(seconds / 3600);  
  200.  
  201.     if (hours < 10) {  
  202.  
  203.         hours = "0" + hours;  
  204.  
  205.     }  
  206.  
  207.     seconds = seconds % 3600;  
  208.  
  209.     var minutes = Math.floor(seconds / 60);  
  210.  
  211.     if (minutes < 10) {  
  212.  
  213.         minutes = "0" + minutes;  
  214.  
  215.     }  
  216.  
  217.     seconds = seconds % 60;  
  218.  
  219.     if (seconds < 10) {  
  220.  
  221.         seconds = "0" + seconds;  
  222.  
  223.     }  
  224.  
  225.     var result = "<span class=\"digit\">" + days + "</span> days <span class=\"digit\">" + hours + "</span> hours <span class=\"digit\">" + minutes + "</span> minutes <span class=\"digit\">" + seconds + "</span> seconds";  
  226.  
  227.     $("#elapseClock").html(result);  
  228.  
  229. }  
  230.  
  231.    
  232.  
  233. function showMessages() {  
  234.  
  235.     adjustWordsPosition();  
  236.  
  237.     $('#messages').fadeIn(5000, function() {  
  238.  
  239.         showLoveU();  
  240.  
  241.     });  
  242.  
  243. }  
  244.  
  245.    
  246.  
  247. function adjustWordsPosition() {  
  248.  
  249.     $('#words').css("position", "absolute");  
  250.  
  251.     $('#words').css("top", $("#garden").position().top + 195);  
  252.  
  253.     $('#words').css("left", $("#garden").position().left + 70);  
  254.  
  255. }  
  256.  
  257.    
  258.  
  259. function adjustCodePosition() {  
  260.  
  261.     $('#code').css("margin-top", ($("#garden").height() - $("#code").height()) / 2);  
  262.  
  263. }  
  264.  
  265.    
  266.  
  267. function showLoveU() {  
  268.  
  269.     $('#loveu').fadeIn(3000);  
  270.  
  271. }
  272.  

回复 "var $window = $(window), gardenCtx, gard"

这儿你可以回复上面这条便签

captcha