最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

jquery div 居中技巧應用介紹

 更新時間:2012年11月24日 15:27:31   作者:  
在項目實戰(zhàn)中碰到了一些問題,例如,jquery如何使div居中,此問題一直困擾著我,因此尋找了一些方法,曬出來和大家分享一下
very short version:
[html]
復制代碼 代碼如下:

$('#myDiv').css({top:'50%',left:'50%',margin:'-'+($('#myDiv').height() / 2)+'px 0 0 -'+($('#myDiv').width() / 2)+'px'});
$('#myDiv').css({top:'50%',left:'50%',margin:'-'+($('#myDiv').height() / 2)+'px 0 0 -'+($('#myDiv').width() / 2)+'px'});

short version:
[html]
復制代碼 代碼如下:

(function($){
$.fn.extend({
center: function () {
return this.each(function() {
var top = ($(window).height() - $(this).outerHeight()) / 2;
var left = ($(window).width() - $(this).outerWidth()) / 2;
$(this).css({position:'absolute', margin:0, top: (top > 0 ? top : 0)+'px', left: (left > 0 ? left : 0)+'px'});
});
}
});
})(jQuery);
(function($){
$.fn.extend({
center: function () {
return this.each(function() {
var top = ($(window).height() - $(this).outerHeight()) / 2;
var left = ($(window).width() - $(this).outerWidth()) / 2;
$(this).css({position:'absolute', margin:0, top: (top > 0 ? top : 0)+'px', left: (left > 0 ? left : 0)+'px'});
});
}
});
})(jQuery);

Activated by this code :
復制代碼 代碼如下:

$('#mainDiv').center();

[javascript]
復制代碼 代碼如下:

(function($){
$.fn.extend({
center: function (options) {
var options = $.extend({ // Default values
inside:window, // element, center into window
transition: 0, // millisecond, transition time
minX:0, // pixel, minimum left element value
minY:0, // pixel, minimum top element value
withScrolling:true, // booleen, take care of the scrollbar (scrollTop)
vertical:true, // booleen, center vertical
horizontal:true // booleen, center horizontal
}, 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).outerWidth()) / 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);
[code]
(function($){
$.fn.extend({
center: function (options) {
var options = $.extend({ // Default values
inside:window, // element, center into window
transition: 0, // millisecond, transition time
minX:0, // pixel, minimum left element value
minY:0, // pixel, minimum top element value
withScrolling:true, // booleen, take care of the scrollbar (scrollTop)
vertical:true, // booleen, center vertical
horizontal:true // booleen, center horizontal
}, 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).outerWidth()) / 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);

PLUGIN VERSION
[javascript]
復制代碼 代碼如下:

(function($){
$.fn.extend({
center: function (options) {
var options = $.extend({ // Default values
inside:window, // element, center into window
transition: 0, // millisecond, transition time
minX:0, // pixel, minimum left element value
minY:0, // pixel, minimum top element value
withScrolling:true, // booleen, take care of the scrollbar (scrollTop)
vertical:true, // booleen, center vertical
horizontal:true // booleen, center horizontal
}, 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).outerWidth()) / 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);

復制代碼 代碼如下:

(function($){
$.fn.extend({
center: function (options) {
var options = $.extend({ // Default values
inside:window, // element, center into window
transition: 0, // millisecond, transition time
minX:0, // pixel, minimum left element value
minY:0, // pixel, minimum top element value
withScrolling:true, // booleen, take care of the scrollbar (scrollTop)
vertical:true, // booleen, center vertical
horizontal:true // booleen, center horizontal
}, 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).outerWidth()) / 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);

Activated by this code :
復制代碼 代碼如下:

$(document).ready(function(){
$('#mainDiv').center();
$(window).bind('resize', function() {
$('#mainDiv').center({transition:300});
});
);

觀此人JS代碼,讓人嘆為觀止。
簡潔明了。卻又舉一反三。

相關(guān)文章

  • jQuery基于json與cookie實現(xiàn)購物車的方法

    jQuery基于json與cookie實現(xiàn)購物車的方法

    這篇文章主要介紹了jQuery基于json與cookie實現(xiàn)購物車的方法,涉及jQuery操作json格式數(shù)據(jù)與cookie存儲購物車信息的相關(guān)技巧,需要的朋友可以參考下
    2016-04-04
  • 基于Jquery實現(xiàn)表格動態(tài)分頁實現(xiàn)代碼

    基于Jquery實現(xiàn)表格動態(tài)分頁實現(xiàn)代碼

    項目中經(jīng)常會對表格進行分頁,以下運用jquery對用戶管理中的用戶表格進行分頁。
    2011-06-06
  • jquery submit()不能提交表單的解決方法

    jquery submit()不能提交表單的解決方法

    這篇文章主要為大家詳細介紹了jquery submit()不能提交表單的解決方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-04-04
  • jQuery中綁定事件的命名空間詳解

    jQuery中綁定事件的命名空間詳解

    jQuery的bind的函數(shù)在實際應用其實不是特別多,只是他可以綁定一個事件,但不會即時觸發(fā),也可以通過unbind來解除綁定。
    2011-04-04
  • 檢測jQuery.js是否已加載的判斷代碼

    檢測jQuery.js是否已加載的判斷代碼

    測類、方法、變量或?qū)傩允欠褚汛嬖?,這是Javascript編程基礎知識。在這里我們就是要檢測jQuery()或$()函數(shù)是否存在
    2011-05-05
  • 淺談jQuery中的checkbox問題

    淺談jQuery中的checkbox問題

    下面小編就為大家?guī)硪黄獪\談jQuery中的checkbox問題。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2016-08-08
  • jQuery EasyUI API 中文文檔 - Documentation 文檔

    jQuery EasyUI API 中文文檔 - Documentation 文檔

    jQuery EasyUI API 中文文檔 - Documentation 文檔,使用jQuery EasyUI的朋友可以參考下。
    2011-09-09
  • 最新評論

    唐河县| 屏东县| 徐闻县| 尚义县| 柳州市| 怀安县| 灌云县| 宿州市| 北流市| 平江县| 社旗县| 日照市| 射阳县| 万荣县| 尖扎县| 尼木县| 名山县| 新干县| 无为县| 静安区| 同德县| 新宁县| 阿尔山市| 彭泽县| 石景山区| 白水县| 理塘县| 上虞市| 东兴市| 托克托县| 凤翔县| 宜阳县| 巴林右旗| 浦北县| 页游| 民权县| 明星| 长岛县| 祁连县| 霍州市| 德州市|