<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      隨機(jī)字符變換效果的jQuery插件開發(fā)教程

      來源:tutorialzine.com         編譯:GBin1.com

       

      在這篇快速的jQuery插件開發(fā)教程中,我們將創(chuàng)建一個jQuery插件用來隨機(jī)排序顯示任何一個DOM元素的文字內(nèi)容 -這將會是一個非常有趣的效果,可以用在標(biāo)題,logo及其幻燈效果中。

       

      隨機(jī)字符變換效果的jQuery插件開發(fā)教程

       

      在線演示       在線下載

       

      代碼片段

      那么第一部呢,我們將開發(fā)jQuery插件的基本架構(gòu)。我們將把代碼放入一個自運(yùn)行的方法中,并且擴(kuò)展$.fn.

      assets/js/jquery.shuffleLetters.js

      (function($){
          $.fn.shuffleLetters = function(prop){
              // Handling default arguments
              var options = $.extend({
                  // Default arguments
              },prop)
              return this.each(function(){
                  // The main plugin code goes here
              });
          };
          // A helper function
          function randomChar(type){
              // Generate and return a random character
          }
      })(jQuery);

      下一步我們將關(guān)注與randomChar()方法。它將會接受一個類型參數(shù)(Lowerletter, upperletter或者symbol),并且返回一個隨機(jī)字符。

      function randomChar(type){
          var pool = "";
          if (type == "lowerLetter"){
              pool = "abcdefghijklmnopqrstuvwxyz0123456789";
          }
          else if (type == "upperLetter"){
              pool = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
          }
          else if (type == "symbol"){
              pool = ",.?/\\(^)![]{}*&^%$#'\"";
          }
          var arr = pool.split('');
          return arr[Math.floor(Math.random()*arr.length)];
      }

      我們本應(yīng)該使用一個簡單的字符池來保存所有的字符,但是這樣會有更好效果。

      現(xiàn)在我們來書寫插件的body部分:

      $.fn.shuffleLetters = function(prop){
      
          var options = $.extend({
              "step"    : 8,    // How many times should the letters be changed
              "fps"    : 25,    // Frames Per Second
              "text"    : ""     // Use this text instead of the contents
          },prop)
      
          return this.each(function(){
              var el = $(this),
                  str = "";
              if(options.text) {
                  str = options.text.split('');
              }
              else {
                  str = el.text().split('');
              }
              // The types array holds the type for each character;
              // Letters holds the positions of non-space characters;
              var types = [],
                  letters = [];
              // Looping through all the chars of the string
              for(var i=0;i<str.length;i++){
                  var ch = str[i];
                  if(ch == " "){
                      types[i] = "space";
                      continue;
                  }
                  else if(/[a-z]/.test(ch)){
                      types[i] = "lowerLetter";
                  }
                  else if(/[A-Z]/.test(ch)){
                      types[i] = "upperLetter";
                  }
                  else {
                      types[i] = "symbol";
                  }
                  letters.push(i);
              }
              el.html("");            
              // Self executing named function expression:
              (function shuffle(start){
                  // This code is run options.fps times per second
                  // and updates the contents of the page element
                  var i,
                      len = letters.length,
                      strCopy = str.slice(0);    // Fresh copy of the string
                  if(start>len){
                      return;
                  }
                  // All the work gets done here
                  for(i=Math.max(start,0); i < len; i++){
      
                      // The start argument and options.step limit
                      // the characters we will be working on at once
      
                      if( i < start+options.step){
                          // Generate a random character at this position
                          strCopy[letters[i]] = randomChar(types[letters[i]]);
                      }
                      else {
                          strCopy[letters[i]] = "";
                      }
                  }
                  el.text(strCopy.join(""));
                  setTimeout(function(){
                      shuffle(start+1);
                  },1000/options.fps);
              })(-options.step);
          });
      };

      這 個插件將可以接受被調(diào)用的DOM元素的內(nèi)容,或者當(dāng)作一個參數(shù)傳入的對象的text屬性。然后它分割字符串到字符,并且決定使用的類型。這個 shuffle功能使用setTimeout()來調(diào)用自己并且隨機(jī)生成字符串,更新DOM元素。如果你不清楚setTimeout()的使用,可以參考 這篇文章:http://www.gbin1.com/technology/jqueryhowto/fadeoutonebyone/ , 調(diào)用seTimeout方法可以幫助你按特定時間間隔執(zhí)行某些操作。

       

      原文來自:隨機(jī)字符變換效果的jQuery插件開發(fā)教程

      posted @ 2011-10-22 10:43  igeekbar  閱讀(251)  評論(0)    收藏  舉報

      中文互聯(lián): GBin1.com | RSS訂閱 | 郵件訂閱 | 手機(jī)訂閱

      主站蜘蛛池模板: 阿荣旗| 欧美日韩一区二区三区视频播放| 钟山县| 精品久久人人妻人人做精品| 欧美福利电影A在线播放| 国产av麻豆mag剧集| 午夜高清福利在线观看| 天天澡日日澡狠狠欧美老妇| 又爽又黄又无遮挡的激情视频| 在厨房拨开内裤进入在线视频| 在国产线视频A在线视频| 亚洲精品成人老司机影视| 激情综合五月丁香亚洲| 国产精品亚洲二区在线播放| 国产目拍亚洲精品二区| 色视频不卡一区二区三区| 91久久性奴调教国产免费| 国产精品av免费观看| 亚洲天堂成人一区二区三区 | 色欲AV无码一区二区人妻| 综合无码一区二区三区| 亚洲色欲色欲www| 亚洲中文字幕久在线| 国产欧美亚洲精品a| 国产性色的免费视频网站| 五月花成人网| 97se亚洲国产综合在线| 国产精品免费看久久久无码| 狠狠综合久久综合88亚洲爱文| 中国老太婆video| 9999国产精品欧美久久久久久| 国产无遮挡猛进猛出免费| 亚洲AV无码乱码在线观看性色扶 | 亚洲一区二区色情苍井空| 亚洲综合一区二区三区在线| 国产av永久无码天堂影院| 99精品国产成人一区二区| 亚洲国产精品一二三四五| 久久精品国产只有精品96| 91福利一区福利二区| 欧美大bbbb流白水|