zepto扩展outerWidth与outerHeight方法

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了zepto扩展outerWidth与outerHeight方法相关的知识,希望对你有一定的参考价值。

扩展outerWidth,outerHeight方法

(function($){
    "use strict";

    [‘width‘,‘height‘].forEach(function(dimension){

        var Dimension = dimension.replace(/./,function(m){
            return m[0].toUpperCase();
        });

        //outerWidth or outerHeight

        $.fn[‘outer‘ + Dimension] = function(margin) {
            var elem = this;

            if(elem) {


                // elem.width(); or  elem.height();
                var size = elem[dimension]();

                var sides = {
                    ‘width‘ : [‘left‘, ‘right‘],
                    ‘height‘ : [‘top‘, ‘bottom‘]
                };

                sides[dimension].forEach(function(side){
                    if(margin) {
                        size += parseInt(elem.css(‘margin-‘+side),10);
                    }
                });

                return size;
            } else {
                return null;
            }
        }


    });
})($);

 

以上是关于zepto扩展outerWidth与outerHeight方法的主要内容,如果未能解决你的问题,请参考以下文章

zepto与jquery冲突

使用 jQuery 方法扩展 Zepto.js?滚动顶部()

JavaScript课程——Day23(插件Zepto)

如何让一个宽高不固定的Div在空页面上水平居中且垂直居中?

读zepto源码之工具函数

使用$(window).width(),window.outerWidth,window.innerWidth,document.documentElement.clientWidth,documen