我正在使用jQuery.innerfade插件,它没有响应:::我在jQuery中编写了一些非常好用的东西:::只是想知道这是否是最佳编码,因为我没有很多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);
});
答案 0 :(得分: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);
});