2012-02-05 59 views
-4

我有以下jQuery代碼,我喜歡將其轉換爲原型。將jQuery轉換爲原型

P.S.我的天啊!您的文章沒有什麼太大的上下文解釋代碼段;請更清楚地解釋你的情況。

$(function() { 

    // Set up variables 
    var $el, $parentWrap, $otherWrap, 
     $allTitles = $("dt").css({ 
      padding: 5, // setting the padding here prevents a weird situation, where it would start animating at 0 padding instead of 5 
      "cursor": "pointer" // make it seem clickable 
     }), 
     $allCells = $("dd").css({ 
      position: "relative", 
      top: -1, 
      left: 0, 
      display: "none" // info cells are just kicked off the page with CSS (for accessibility) 
     }); 

    // clicking image of inactive column just opens column, doesn't go to link 
    $("#page-wrap").delegate("a.image","click", function(e) { 

     if (!$(this).parent().hasClass("curCol")) {   
      e.preventDefault(); 
      $(this).next().find('dt:first').click(); 
     } 

    }); 

    // clicking on titles does stuff 
    $("#page-wrap").delegate("dt", "click", function() { 

     // cache this, as always, is good form 
     $el = $(this); 

     // if this is already the active cell, don't do anything 
     if (!$el.hasClass("current")) { 

      $parentWrap = $el.parent().parent(); 
      $otherWraps = $(".info-col").not($parentWrap); 

      // remove current cell from selection of all cells 
      $allTitles = $("dt").not(this); 

      // close all info cells 
      $allCells.slideUp(); 

      // return all titles (except current one) to normal size 
      $allTitles.animate({ 
       fontSize: "14px", 
       paddingTop: 0, 
       paddingRight: 0, 
       paddingBottom: 0, 
       paddingLeft: 0 
      }); 

      // animate current title to larger size    
      $el.animate({ 
       "font-size": "20px", 
       paddingTop: 0, 
       paddingRight: 0, 
       paddingBottom: 0, 
       paddingLeft: 0 
      }).next().slideDown(); 

      // make the current column the large size 
      $parentWrap.animate({ 
       width: 320 
      }).addClass("curCol"); 

      // make other columns the small size 
      $otherWraps.animate({ 
       width: 128 
      }).removeClass("curCol"); 

      // make sure the correct column is current 
      $allTitles.removeClass("current"); 
      $el.addClass("current"); 

     } 

    }); 

    $("#starter").trigger("click"); 

}); 

任何幫助,非常感謝。

+0

你的問題是不清楚的,你的代碼已經看起來是用jQuery編寫的... – 2012-02-05 11:05:52

+0

你正在使用jQuery,你到底想要達到什麼目標? – clem 2012-02-05 11:06:36

+0

此代碼不適用於原型 – 2012-02-05 11:13:38

回答

0

如果您想同時使用Prototype和jQuery,您可以使用jQuery's no confilct,它將$變量的用法重新分配給Prototype,並且您可以在同一個網站上使用這兩者。

+0

然後我必須使用:'jQuery.noConflict(); (函數($){'代碼之前和'})(jQuery);'在代碼結束? – 2012-02-05 11:32:32

+0

您應該在加載jQuery庫後立即使用noConflict。那麼在你的代碼中確保你使用了任何你指定的jquery變量來代替$。例如$ j = jQuery.nocConflict()然後你必須使用$ j而不是$當使用jQuery。 – clem 2012-02-05 11:35:59

+0

很好,謝謝 – 2012-02-05 11:53:51