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

jquery水平可左右滚动的时间线插件

一款水平滚动时间线插件,可以从HTML无序的数据列表中生成一个水平滚动的时间线,带左右箭头滚动。
  其它&杂项
 174  

15种富有创意的自定义标题文字模板风格

15种以上CSS标题示例,每个样式都使用CSS创建,可很容易的用于HTML代码中。从下划线到字体间距和字体变化,非常的有新意。
  其它&杂项
 159  

js创建的视差堆叠卡片效果

一款滚动页面触发的堆叠卡片特效,使用CSS粘性位置和Intersection Observer创建堆叠卡片效果。
  其它&杂项
 170  

jquery跟随鼠标移动的垂直滚动进度条特效代码

一个跟随鼠标移动的垂直进度条插件,其百分比值始终位于光标后面,当滚动网页时实时显示当前百分比进度。
  其它&杂项
 369  

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

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