jquery轻量级DIV容器自动等高插件

所属分类: 网页特效-其它&杂项    2023-11-16 11:16:17

jquery轻量级DIV容器自动等高插件 ie兼容6
 查看演示  登录后下载 温馨提示
登录会员即可享受免费下载
 我要建站

jquery轻量级DIV容器自动等高插件(共3个文件)

    • index.html

使用方法

;(function($) {"use strict"; 
// Name and default settings
var pluginName = 'align';
var resizeName = pluginName + 'ResizeDone';
var defaults = {
    bottom: false,
    selector: '> *'
};

// Resize timer
var resizeTimer;

// Map commands to methods
var commands = {
    update: 'update',
    reset: 'reset'
};

// Constructor
var Plugin = function(element, options) {
    this.element = element;
    this.settings = $.extend({}, defaults, options);
    this._defaults = defaults;
    this._name = pluginName;

    // Initialization
    this.init();
};

// Initialization
Plugin.prototype.init = function() {
    var _this = this;

    this.select();

    // Align boxes when the complete page has loaded and when the window has
    // finished resizing. It's no good trying to align everything on
    // document ready because you might still be waiting for CSS that will
    // affect the height of the boxes.
    $(window).on('load ' + resizeName, function() {
        _this.align();
    });

    // Attempt to align the boxes immediately as well, in case we are
    // running on window load instead of on DOM content ready.
    _this.align();
};

// Select boxes to align
Plugin.prototype.select = function() {
    this.boxes = $(this.element).find(this.settings.selector);
    this.save();
};

// Save initial styles
Plugin.prototype.save = function() {
    this.boxes.each(function(i, boxElement) {
        var box = $(boxElement);

        if (box.attr('style') && !box.data('style')) {
            box.data('style', box.attr('style'));
        }
    });
};

// Reset boxes to their initial styles
Plugin.prototype.reset = function() {
    this.naturalize();
    this.boxes.each(function(i, boxElement) {
        var box = $(boxElement);

        // Restore original style attribute
        if (box.data('style')) {
            return box.attr('style', box.data('style'));
        }

        // Remove style attribute added by this plugin
        box.removeAttr('style');
    });
};

// Set all boxes to their natural height
Plugin.prototype.naturalize = function() {
    this.boxes.each(function(i, boxElement) {
        $(boxElement).height('auto');
    });
};

// Align boxes
Plugin.prototype.align = function() {
    var _this = this;
    var boxes = _this.boxes;
    var done = [];

    // Reset box heights
    this.naturalize();

    boxes.each(function(i, boxElement) {
        var box = $(boxElement);
        var max = 0;

        // Assemble collection of elements in the same row
        var row = box.add(boxes.not(box).filter(function() {
            var heightA = box.offset().top;
            var heightB = $(this).offset().top;

            // Align to bottom edge instead?
            if (_this.settings.bottom) {
                heightA += box.height();
                heightB += $(this).height();
            }

            return heightA === heightB;
        }));

        // If only box in row or already resized, do nothing
        if (row.length === 1 || $.inArray(boxElement, done) !== -1) {
            return;
        }

        // Find the tallest element in the row
        row.each(function(i, siblingElement) {
            var sibling = $(siblingElement);
            var height = sibling.outerHeight();

            if (height > max) {
                max = height;
            }

            // We are finished with this element, so don't check it again
            done.push(siblingElement);
        });

        // Set all elements to same height as tallest element in row
        row.each(function(i, siblingElement) {
            return $(siblingElement).outerHeight(max);
        });
    });
};

// Update selection and re-align all boxes
Plugin.prototype.update = function() {
    this.select();
    this.align();
};

// Add method to jQuery
$.fn[pluginName] = function(options) {
    return this.each(function() {
        var instance = $.data(this, pluginName);

        // Named commands
        if (typeof options === 'string') {
            if (
                typeof instance === 'undefined' ||
                typeof commands[options] === 'undefined'
            ) {
                return false;
            }

            return instance[commands[options]]();
        }

        // Create instance
        if (!instance) {
            $.data(this, pluginName, new Plugin(this, options));
        }
    });
};

// Trigger window resize complete event
$(window).on('resize', function() {
    window.clearTimeout(resizeTimer);

    resizeTimer = window.setTimeout(function() {
        $(window).trigger(resizeName);
    }, 50);
});

})(jQuery);

站长提示:
1. 苦力吧素材官方QQ群:950875342
2. 平台上所有素材资源,需注册登录会员方能正常下载。
3. 会员用户积极反馈网站、素材资源BUG或错误问题,每次奖励2K币
4. PHP源码类素材,如需协助安装调试,或你有二次开发需求,可联系苦力吧客服。
5. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服
相关资源 / 其它&杂项

jquery随机洗牌打乱列表数据顺序插件

一款打乱列表顺序插件,使用fisher-yates shuffle算法来扰乱列表数据元素。
  其它&杂项
 3236  0

jquery动态移除指定DIV标记内标签属性特效代码

鼠标点击按钮,可针对某个DIV移除指定标签,使用起来非常简单!
  其它&杂项
 7279  0

jQuery文字大小自适应屏幕特效

调整浏览器屏幕文字大小自适应效果,文字随着屏幕大小自动改变字号。
  其它&杂项
 4226  0

jquery实时监听目标属性标签值更改插件

当值发生变化时触发内置函数并回调,使用DOM的MutationObserver API,并回退到setInterval,以轮询不兼容浏览器的更改。 允许在单个DOM元素上使用多个监视处理程序,并支持子元素。
  其它&杂项
 6242  0

评论数(0) 回复有机会获得K币 用户协议

^_^ 还没有人评论,快来抢个沙发!
😀
  • 😀
  • 😊
  • 😂
  • 😍
  • 😑
  • 😷
  • 😵
  • 😛
  • 😣
  • 😱
  • 😋
  • 😎
  • 😵
  • 😕
  • 😶
  • 😚
  • 😜
  • 😭
发表评论