jQueryシミュレーションハッカー帝国マトリックス効果例

2391 ワード

この例では,jQueryがハッカー帝国マトリクス効果をシミュレートする方法について述べた.皆さんの参考にしてください.具体的な実現方法は以下の通りである.
htmlセクションは次のとおりです.

10001001110010010010000
the answer is in your mind

cssセクションは次のとおりです.

#container div{padding:10px;position:absolute;border:0px dotted brown;width:0px;color:green;text-shadow: 1px 1px 3px #cccccc;}
.text{padding:10px;color:#ccc;}
#panel{width:400px;margin:0 auto;color:white;margin-top:20%;font-size:15px;font-weight:bold;z-index:99999;background:black;}


jsセクションは次のとおりです.

$(function() {
  for (var i = 0; i < 3; i++) $('div', '#container').clone().prependTo('#container');
  //        
  range();
  setInterval(drop, 150); //  150  
});
//  
function range() {
  var num = 1;
  $('div', '#container').each(function(i) {
    var ww = $(window).width(); //    
    var wh = $(window).height();
    var ol = $(this).offset().left; //     
    var ot = -20; //$(this).offset().top;//       
    i++;
    if (i % 22 == 0) num = 1; //22   
    $(this).css({
      "left": (ol + num * 60) + "px",
      "top": (ot + Math.ceil(i / 2) * 30) + "px"
    }); //      ,      
    num++;
  });
}
//  
function drop() {
  $('div', '#container').each(function(i) {
    var wh = $(window).height();
    var ol = $(this).offset().left;
    var ot = $(this).offset().top;
    var rnd = Math.round(Math.random() * 100);
    var rnd2 = Math.round(Math.random() * 50);
    //i = i == 0 ? 0.5 : i;
    $(this).css({
      "top": (ot + rnd + rnd2) + "px"
    }); //     
    if (ot >= wh) //        
    {
      //$(this).css({"top":wh-20 +"px"});
      //               
      $(this).css({
        "top": -5 * rnd + "px"
      }); //       
    }
  });
}


本文で述べたことが皆さんのjQueryプログラム設計に役立つことを願っています.