設定div始終置中顯示,設定div置中顯示

來源:互聯網
上載者:User

設定div始終置中顯示,設定div置中顯示

<script type="text/javascript">(function($){    $.fn.extend({        center:function(options){        //center外掛程式            var options=$.extend({       //預設屬性值                inside:window,           //元素居於表單中心                transition:0,            //元素置中移動時的時間,單位是millisecond                minX:0,                  //元素最小X方向距邊值                minY:0,                  //元素最小Y方向距邊值                withScrolling:true,      //是否支援捲軸                vertical:true,           //是否支援垂直置中                horizontal:true          //是否支援水平置中            },options);        return this.each(function(){     //通過計算視窗尺寸與元素尺寸將元素置中顯示            var props={position:'absolute'};            if(options.vertical){                var top=($(options.inside).height()-$(this).outerHeight())/2;                if(options.withScrolling) top+=$(options.inside).scrollTop()||0;                top=(top>options.minY?top:options.minY);                $.extend(props,{top:top+'px'});            }            if (options.horizontal) {                var left=($(options.inside).width()-$(this).outerHeight())/2;                if(options.withScrolling) left+=$(options.inside).scrollLeft()||0;                left=(left>options.minX?left:options.minX);                $.extend(props,{left:left+'px'});            }            if(options.transition>0)$(this).animate(props,options.transition);            else $(this).css(props);            return $(this);        });        }    });})(jQuery);</script><script type="text/javascript">$(document).ready(function(){    $("#centerDiv").center();    $(window).bind('resize',function(){        $("#centerDiv").center({transition:500});    });});</script></head><body>    <div id="centerDiv" style="height: 100px;width: 200px;background: #ccf">設定div始終置中顯示</div></body>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.