jquery实现居中弹出浮动层代码
时间:2010-08-31 来源:缘分星空
基于jquery的居中弹出层效果代码,需要的朋友可以参考下核心的代码。
/*
弹出窗口定位到浏览器中间
1. show(options{
self._resetPosition = function() {
self._container.css("top", self._getTop());
self._container.css("left", self._getLeft());
};
self._getTop = function() {
return Q.bom.scrollY() + (Q.bom.windowHeight() - self._options.height) / 2;
};
self._getLeft = function() {
return (Q.dom.pageWidth() - self._options.width) / 2;
};
self.show = function(options) {
self._options = $.extend({
width: 350,
self._container = self._options.container;
var css = {
'width': self._options.width,
'height': self._options.height,
'z-index': Q.Overlay.zindex,
'position': 'absolute',
'left': self._getLeft(),
'top': self._getTop(),
'display': 'none'
};
self._container.css(css);
if (self._options.model) {
self._overlay = new Q.Overlay(self._options.opacity);
self._overlay.show();
}
$(window).scroll(self._resetPosition);
$(window).resize(self._resetPosition);
$(document.body).append(self._container);
self._container.fadeIn(self._options.speed);
Q.Overlay.zindex++; //没弹出一次就递增,防止多个弹层重叠
};
self.close = function(speed) {
$(window).unbind('resize', self._resetPosition);
$(window).unbind('scroll', self._resetPosition);
self._container.fadeOut(speed || 0, function() {
self._container.remove();
if (self._options.model) {
self._overlay.close();
}
});
};
};
这里居中是通过js控制的,下面是几个用这个剧中Panel实现的通用对话框
/*弹出自定义隐藏框
<div id="league" style="display:none">
<button class="close" >close</button>
</div>
Q.showPanel("league", function(panel, container) {
container.find(".close").click(function() {
panel.close();
}
);
*/
Q.showPanel = function(containerId, registerEventCallback) {
var container = $("#" + containerId);
var height = container.height();
var width = container.width();
container = container.clone(true);
var options = {
var panel = new Q.Panel();
registerEventCallback(panel, container);
panel.show(options);
};
/*弹出窗口,从url加载窗体html片段*/
Q.openWindow = function(url, data, registerEventCallback) {
$.get(url, data, function(html) {
var panelDiv = $(html);
panelDiv.hide();
$(document.body).append(panelDiv);
var options = {
var panel = new Q.Panel();
registerEventCallback(panel, panelDiv);
panel.show(options);
});
}
/*提示框,3秒后自动淡出*/
Q.tips = function(msg) {
var html = '<div class="gu_layer w330">' +
'<div class="gu_layer_main">' +
'<h2><img class="icon_layer_corner" alt="" src="http://res.fetionpic.com/img/blank/spacer.gif">提示</h2>' +
'<p class="gu_layer_txt">' + msg + '</p>' +
'<div class="gu_layer_btn"></div>' +
'</div></div>'
var container = $(html);
container.hide();
$(document.body).append(container);
var panel = new Q.Panel();
panel.show({ container: container,
setTimeout(function() { panel.close(500); }, 3000);
};
/*提示框*/
Q.alert = function(msg) {
var html = '<div class="gu_layer w330">' +
'<div class="gu_layer_main">' +
'<h2><img class="icon_layer_corner" alt="" src="http://res.fetionpic.com/img/blank/spacer.gif"><a class="btn_tit_close" href="">关闭</a>提示</h2>' +
'<p class="gu_layer_txt">' + msg + '</p>' +
'<div class="gu_layer_btn"><a class="btn_org" href="">确 定</a></div>' +
'</div></div>'
var container = $(html);
container.hide();
$(document.body).append(container);
var panel = new Q.Panel();
container.find(".btn_tit_close").click(function() {
panel.close();
return false;
});
container.find(".btn_org").click(function() {
panel.close();
return false;
});
panel.show({ container: container,
};
/*确认框 cancel回调为可选*/
Q.confirm = function(title, msg, yes, cancel) {
var html = '<div class="gu_layer w330">' +
'<div class="gu_layer_main">' +
'<h2><img class="icon_layer_corner" alt="" src="http://res.fetionpic.com/img/blank/spacer.gif"><a class="btn_tit_close" href="">关闭</a>' + title + '</h2>' +
'<p class="gu_layer_txt">' + msg + '</p>' +
'<div class="gu_layer_btn"><a class="btn_org" href="">确 定</a><a class="btn_gray" href="">取 消</a></div>' +
'</div></div>'
var container = $(html);
container.hide();
$(document.body).append(container);
var panel = new Q.Panel();
container.find(".btn_tit_close").click(function() {
panel.close();
return false;
});
container.find(".btn_gray").click(function() {
if (cancel)
cancel();
panel.close();
return false;
});
container.find(".btn_org").click(function() {
if (yes)
yes();
panel.close();
return false;
});
panel.show({ container: container,
};
Louis Vuitton Suhali Leather Lockit MM Black M91875 HandbagsChanel Handbags Chanel Coco Cabas Black Vinyl 34502- metallic gol Chanel-34502-metallic-goldLarge Multifunction Tote - Black chanel-cc2330 Handbagschanel Handbags Chanel 2008 summer Clutch 2223 - black chanel-2223--blackGucci Designers Handbags 189895HX61G9643 gucci-189895HX61G9643Gucci GG Fabric Handbagss G169976E Gucci-169976ENew Handbags CC207 chanel-207blackLouis Vuitton Damier Canvas Recoleta N51299 HandbagsLouis Vuitton Damier Canvas Cosmetic Case N47543 HandbagsGucci Designers Handbags 211975FAF4X1000 gucci-211975FAF4X1000LV M95311 Louis Vuitton Handbags Musette - Red TrimChanel Classic Flap Black Crocodile Veins Leather 36002 36002black HandbagsNew Caviar Leather Chain Tote Bag - Red chanel-35899-red HandbagsLouis Vuitton Monogram Mirage Griet M95579 HandbagsGucci Designers Handbags 189895HX61G4061 gucci-189895HX61G4061Chanel Handbags Chanel 35929-Red Chanel-CH35929ALouis Vuitton Show Spring Summer 2009 Kalahari PM M97016 HandbagsGucci bag 208940-Black gucci-208940-Black HandbagsChanel Handbags 1112-Green and Silver Chain Chanel-1112-GreenLouis Vuitton Show Spring And Summer 2009 Flight Bag Savane Red M97006 HandbagsLouis Vuitton Monogram Vernis Sunset Boulevard White LV M93541WT HandbagsLouis Vuitton Monogram Canvas Trotteur Beauboure M97037 HandbagsLouis Vuitton Epi Leather Pont-Neuf GM M59042-Red HandbagsGucci Hysteria bag-Pink 189588-01 HandbagsLouis Vuitton 2008 Collection Salina PM M95613 HandbagsLV m92802 Louis Vuitton Scuba PM Fuschia Handbags Fuschiam92802Louis Vuitton AAAAA Grade Crocodile Veins Leather Top Handle Bag - Greenish Gray HandbagsGucci Race Top Handle Bag in White patent Leather Gucci-177091-03 HandbagsGucci 200713-Evening Bag in Pink Gucci-200713H HandbagsLouis Vuitton Monogram Canvas Batignolles Vertical M51153 HandbagsGucci GG Fabric Handbagss 137396 gucci-137396Gucci GG Fabric Handbagss G197395 Gucci-197395LV M95220 Louis Vuitton LV Handbags Mini Lin Saumur XLLV M95557 Louis Vuitton Handbags Bequia Document BagLarge Multifunction Tote - Chocolate chanel-cc2340 HandbagsGucci bag 203527 in Black Patent Leather Gucci-5-203527 HandbagsGucci leather messenger bag-White gucci-148476-white HandbagsGucci GG Fabric Handbagss 177091-Brown gucci-177091-WhiteLouis Vuitton Monogram With tassels Shoulder Bag Black M95867 HandbagsGucci bag 203518 in Black Patent Leather Gucci-5-203518 HandbagsGucci bag 197022-Black Gucci-197022-Black HandbagsGucci G2008565-Guccisima leather Chocolate Gucci-2008565-03 HandbagsLouis Vuitton Monogram Vernis Brentwood Black M91989 HandbagsLouis Vuitton 1:1 Grade Monogram Denim Big Messenger Bag with Tail Charm and Tassels - Green HandbagsLouis Vuitton Monogram Miroir Miroir Alma Silver M95273 HandbagsLV M51286 Louis Vuitton LV Handbags Sarria MiniGucci 154432-Black Evening Bag Gucci-154432B7 HandbagsGucci 220143 BCC8G 1000 medium backpack GUCCI-220143-BCC8G-1000 HandbagsGucci massi black Handbags Gucci 150336-02 Louis Vuitton Monogram Mini Lin Manon Mini Pouch M95668 Handbags
相关阅读 更多 +