2012-11-27 93 views
1

我正在使用jQuery.innerfade插件,它沒有響應:::我在jQuery中編寫了一些工作得很好的東西:::只是想知道這是否是最優編碼,因爲我沒有很多jQuery的知識:::爲innerfade優化jQuery代碼

// Set container height 
    var innerfade_H = $('#blog_link .container').height(); 
    $("#blog_link .container").css("height", innerfade_H); 

    // Resize innerfade on resize 
    function resize_innerfade() { 
     $('#blog_link .container, .blog_link').css("height", ""); //clear heights we will be adding new height 
     $('.blog_link li').css("position", ""); //clear position this is so we can calculate the actual height 

     var innerfade_Resize = $('.blog_link').height(); //get new height 

     $("#blog_link .container, .blog_link").css("height", innerfade_Resize); //set the new height 
     $('.blog_link li').css("position", "absolute"); // reset position to absolute 
    }; 

     // On resize lets put everything into motion little timer so screenwidth settles 
     var resizeInn; 
     jQuery(window).resize(function() { 
      clearTimeout(resizeInn); 
      resizeInn = setTimeout(resize_innerfade, 200); 
     }); 

回答

1

沒有太多的代碼,但你仍然可以通過緩存選擇,而不是要求他們每一次優化它..

var $container = $('#blog_link .container') ; 
// Set container height 
var innerfade_H = $container.height(); 
$container.css("height", innerfade_H); 

// Resize innerfade on resize 


function resize_innerfade() { 

    var $blog_link = $('.blog_link'); 
    var $blog_li = $('.blog_link li'); 

    $container.add($blog_link).css("height", ""); //clear heights we will be adding new height 
    $blog_li.css("position", ""); //clear position this is so we can calculate the actual height 
    var innerfade_Resize = $blog_link.height(); //get new height 
    $container.add($blog_link).css("height", innerfade_Resize); //set the new height 
    $blog_li.css("position", "absolute"); // reset position to absolute 
}; 

// On resize lets put everything into motion little timer so screenwidth settles 
var resizeInn; 
jQuery(window).resize(function() { 
    clearTimeout(resizeInn); 
    resizeInn = setTimeout(resize_innerfade, 200); 
});​