当前位置: 首页 > news >正文

JQuery 模式窗口插件

 

 

jQuery的模式窗口插件网上有很多,但都有大大小小的问题。始终不能满足我的需求。

前几天在园子里看到  [原创]仿QQ校友DIV模拟窗口 这篇文章

今天闲来无事,把文章中插件的 html 和 css 拿了过来 自己也写了一个插件。

很久没写插件了,就当温习了。写的代码真是太丑了。。

------------------------------------------------------------------------------

先来点效果图

2010032721030644.jpg

 

2010032721042196.jpg

 

---------------------------------------------------------------------------------

代码

 

ContractedBlock.gif ExpandedBlockStart.gif 代码

   
/* *
*jQuery弹出层插件
*
*汤晓华 tension
*
*2010/02/27
http://www.cnblogs.com/tandly
*
*本插件html代码以及css部分来自
http://www.cnblogs.com/fishbin/archive/2010/03/21/1690759.html
*
*
*/


(function($) {
$.fn.box
= function(o) {
o
= $.extend(
{
title:
" 意见反馈 " ,
trigger:
"" ,
parent:
" none " ,
width:
- 1990 ,
height:
- 1990 ,
removeBtn:
false ,
buttons: [],
// buttons: [{ title: "确认", cssClass: "jBox-confirm", click: function(obj) {

// }
// }, { title: "取消", cssClass: "jBox-confirm", click: function(obj) {

// } }],
ok: function() { },
cancel: function() { },
close: function() { }
}, o
|| {});

$(
this ).attr( " box_content " , " true " );

var width
= o.width;
var height
= o.height;



// 弹出框的父容器
var parent;
var thisD
= $( this );
if (o.parent == " none " ) {
parent
= $($( " div " )[ 0 ]);

if (parent == null || parent.attr( " box_content " ) == " true " ) {
parent
= $( " body " );
}
}
else {
parent
= $(o.parent);
}


/* 以下是固定的HTML代码 */

var jBoxHolder
= $( ' <div id="jBoxHolder"></div> ' );
var mask
= $( ' <div class="mask" style="width:0px;height:0px;display: none;"></div> ' );
mask.appendTo(jBoxHolder);
var jBoxWraper
= $( ' <div class="jBox-wraper" style="z-index: 1100; width: ' + width + ' px; visibility: hidden;"></div> ' );
var jBox
= $( ' <div id="jBoxID" class="jBox"></div> ' );
var jBoxHandler
= $( ' <div class="jBox-handler"></div> ' );
var jBoxHandlerTitle
= $( ' <h3> ' + o.title + ' </h3> ' );
var jBoxHandlerClose
= $( ' <input type="button" class="jBox-close" title="关闭"/> ' );
var jBoxContent
= $( ' <div class="jBox-content" style="height: ' + height + ' px; overflow: hidden"></div> ' );
var jBoxStatus
= $( ' <div class="jBox-status"></div> ' );

var jBoxConfirm
= $( ' <input type="button" class="jBox-confirm" title="确认" value="确认"/> ' );
var jBoxCancel
= $( ' <input type="button" class="jBox-confirm" title="取消" value="取消"/> ' );


jBoxWraper.close
= function() {
jBoxWraper.css(
" visibility " , " hidden " );
mask.hide();
}

jBoxWraper.open
= function() {
jBoxWraper.css(
" visibility " , " visible " );
jBoxWraper.cover();
mask.show();
}

// 追加标题和关闭按钮到 jBoxHandlerTitle '<div class="jBox-handler"></div>
jBoxHandlerTitle.appendTo(jBoxHandler);

jBoxHandlerClose.click(function() {
jBoxWraper.close();
o.close(
this , jBoxWraper);
});

jBoxHandlerClose.appendTo(jBoxHandler);

// 头部追加到 jBox <div id="jBoxID" class="jBox"></div>
jBoxHandler.appendTo(jBox);

// 当前对象 $(this) 设置为显示并追加到 jBox <div id="jBoxID" class="jBox"></div>
$( this ).css( " display " , " block " ).appendTo(jBoxContent);

// 内容追加到 jBox <div id="jBoxID" class="jBox"></div>
jBoxContent.appendTo(jBox);


if ( ! o.removeBtn) {

jBoxConfirm.click(function() {
o.ok(
this , jBoxWraper);
});


jBoxCancel.click(function() {
var flag
= o.cancel( this , jBoxWraper);
flag
= ( typeof flag) == ' undefined ' ? true : flag

if (flag) {
jBoxWraper.close();
}
});


// 按钮追加到jBoxStatus '<div class="jBox-status"></div>
jBoxConfirm.appendTo(jBoxStatus);
jBoxCancel.appendTo(jBoxStatus);
}

for (var i = 0 ; i < o.buttons.length; i ++ ) {
var btn
= o.buttons[i];
var mybtn
= $( ' <input type="button" class=" ' + btn.cssClass + ' " id="myBtn_ ' + i + ' " title=" ' + btn.title + ' " value=" ' + btn.title + ' "/> ' );
mybtn.appendTo(jBoxStatus);
mybtn.click(function() {
var id
= $( this ).attr( " id " ).split( ' _ ' )[ 1 ];
o.buttons[id].click(mybtn, jBoxWraper);
});

}

// 底部状态栏目追加到 jBox <div id="jBoxID" class="jBox"></div>
jBoxStatus.appendTo(jBox);

// jBox追加到 jBoxWraper
jBox.appendTo(jBoxWraper);

jBoxWraper.appendTo(jBoxHolder);

parent.append(jBoxHolder);

var left
= $(window).width() / 2 - jBoxWraper.width() / 2 ;
var top
= $(window).height() / 2 - jBoxWraper.height() / 2 ;

jBoxWraper.css({ left: left, top: top });


jBoxWraper.cover
= function() {
var doc
= $(document);
var w
= doc.width();
var h
= doc.height();
mask.css({ width: w, height: h });
}



jBoxWraper.resize
= function() {


var doc
= $(document);
left
= $(window).width() / 2 - jBoxWraper.width() / 2 ;
top
= $(window).height() / 2 - jBoxWraper.height() / 2 ;

left
+= doc.scrollLeft();
top
+= + doc.scrollTop();

// jBoxWraper.css({ left: left, top: top });

jBoxWraper.animate({ left: left, top: top },
300 )

jBoxWraper.cover();
}



$(window).resize(function() {
jBoxWraper.resize();
});


var onFooEndFunc
= function(fn) {
var delay
= 100 ; // 根据实际情况可调整延时时间
var executionTimer;
return function() {
if ( !! executionTimer) {
clearTimeout(executionTimer);
}
// 这里延时执行你的函数
executionTimer = setTimeout(function() {
fn();
}, delay);
};
};

var myfn
= function() {
$(window).resize();
}

window.onscroll
= onFooEndFunc(myfn);

$(o.trigger).click(function() {
jBoxWraper.open();
});
};
})(jQuery);




 

 

 

 DEMO

 http://files.cnblogs.com/tandly/jquery.box.rar

苏州    多云

汤晓华 QQ 1881597 MSN tension1990@hotmail.com

2010 03 27

转载于:https://www.cnblogs.com/tandly/archive/2010/03/27/1698574.html

相关文章:

  • 基于Windows Phone的对讲机
  • Cheatsheet: 2010 04.01 ~ 04.07
  • Windows Phone 7开发版手机即将于下月发行
  • 实现Reporting Service2008 的匿名访问(亲测可行)
  • Reporting Service 学习笔记3 2010,0409
  • win7 与visual stdio 不兼容怎么办
  • [转]为DropdownList设置空白选项
  • ArcSDE vs. Oracle Spatial 14
  • 菜单扩展
  • Windows Phone 7的商务功能依然精彩
  • oracle客户端plsql设置(windows7)
  • 什么是云计算 以及能给我们带来什么
  • 字符串反序
  • Windows Phone 7: A New Kind of Phone
  • 跟我学做c#皮肤美化(五)
  • 《Javascript数据结构和算法》笔记-「字典和散列表」
  • 【从零开始安装kubernetes-1.7.3】2.flannel、docker以及Harbor的配置以及作用
  • Android组件 - 收藏集 - 掘金
  • mongodb--安装和初步使用教程
  • Redis 中的布隆过滤器
  • Spring Cloud Alibaba迁移指南(一):一行代码从 Hystrix 迁移到 Sentinel
  • 从伪并行的 Python 多线程说起
  • 聊聊spring cloud的LoadBalancerAutoConfiguration
  • 嵌入式文件系统
  • 区块链分支循环
  • 世界编程语言排行榜2008年06月(ActionScript 挺进20强)
  • 责任链模式的两种实现
  • 测评:对于写作的人来说,Markdown是你最好的朋友 ...
  • ​学习一下,什么是预包装食品?​
  • "无招胜有招"nbsp;史上最全的互…
  • (11)MATLAB PCA+SVM 人脸识别
  • (c语言版)滑动窗口 给定一个字符串,只包含字母和数字,按要求找出字符串中的最长(连续)子串的长度
  • (附源码)计算机毕业设计ssm基于Internet快递柜管理系统
  • (经验分享)作为一名普通本科计算机专业学生,我大学四年到底走了多少弯路
  • (轉貼) 蒼井そら挑戰筋肉擂台 (Misc)
  • .NET Standard 的管理策略
  • .NET 反射的使用
  • .NET/C# 避免调试器不小心提前计算本应延迟计算的值
  • .net连接oracle数据库
  • .net项目IIS、VS 附加进程调试
  • @RestController注解的使用
  • [ linux ] linux 命令英文全称及解释
  • [ 转载 ] SharePoint 资料
  • [20161214]如何确定dbid.txt
  • [2018-01-08] Python强化周的第一天
  • [ai笔记3] ai春晚观后感-谈谈ai与艺术
  • [AndroidStudio]_[初级]_[修改虚拟设备镜像文件的存放位置]
  • [BZOJ 2142]礼物(扩展Lucas定理)
  • [C#]winform制作圆形进度条好用的圆环圆形进度条控件和使用方法
  • [C#7] 1.Tuples(元组)
  • [CSS]浮动
  • [iHooya]2023年1月30日作业解析
  • [JavaWeb]—Spring入门
  • [Machine Learning] Learning with Noisy Labels
  • [Machine Learning][Part 8]神经网络的学习训练过程