这2个例子都是用原生JS写的,主要是用JS拼接了界面,并未做过多的事件监听。,样式用了Css3的一些特性。

调用方式则为:

 //Alert
Alert.show('我警告你哦~'); //Confirm
Confirm.show('我是确认对话框',function(){
doSomething();
});

组件详情看下面的具体代码:

1.CSS样式

由于这2个组件的样式差不多,所用共用了一样的css,样式代码如下:

/**
* dialog
*/
.dialog {
top:40%;
left:40%;
width: 250px;
min-height: 100px;
position:fixed;
z-index:;
text-align: center;
padding:10px;
border:solid #bcc5c1 1px;
background:#FFF;
border-radius:3px;
-moz-border-radius:3px;
-webkit-border-radius:3px;
padding:0px;
behavior: url(PIE.htc);
} .dialog .dialog-header {
position:relative;
width:100%;
height:30px;
margin:0px;
background:#0CF;
background:linear-gradient(top,#d1d4d3 0%,#c4c7c8 100%);
background:-webkit-linear-gradient(top,#d1d4d3 0%,#c4c7c8 100%);
background:-moz-linear-gradient(top,#d1d4d3 0%,#c4c7c8 100%);
border-radius:3px 3px 0px 0px;
-moz-border-radius:3px 3px 0px 0px;
-webkit-border-radius:3px 3px 0px 0px;
behavior: url(PIE.htc);
} .dialog-header .header-left {
width: auto;
height:auto;
float:left;
margin:7px;
} .dialog-header .header-right {
width: auto;
height:auto;
float:right;
margin:7px;
} .dialog .dialog-content {
font-size:14px;
height:100%;
width:96%;
float:left;
font-family:"Helvetica Neue", Helvetica, Arial, sans-serif;
color:#424242;
padding:5px;
} .dialog-content .content-main {
width: 100%;
min-height: 40px;
line-height:25px;
float:left;
white-space: normal;
} .dialog-content .content-btn {
float:left;
width:100%;
height:28px;
margin-top:10px;
} .btn {
font-family:Arial, Helvetica, sans-serif;
font-size:12px;
text-align:center;
vertical-align:middle;
margin-right:5px;
padding:5px 20px 5px 20px;
text-decoration:none;
border:#c4c7c8 solid 1px;
border-radius:3px;
background:#d1d4d3;
background:linear-gradient(top,#d1d4d3 0%,#c4c7c8 100%);
background:-webkit-linear-gradient(top,#d1d4d3 0%,#c4c7c8 100%);
background:-moz-linear-gradient(top,#d1d4d3 0%,#c4c7c8 100%);
color:#111c24; } .btn:hover {
background:#d1d4d3;
background:linear-gradient(top,#c4c7c8 0%,#d1d4d3 100%);
background:-webkit-linear-gradient(top,#c4c7c8 0%,#d1d4d3 100%);
background:-moz-linear-gradient(top,#c4c7c8 0%,#d1d4d3 100%);
color:#111c24;
} .alert-content {
text-align: left;
text-indent: 20px;
} .alert {
margin-left:140px;
}

2.Alert

Alert 主要是模拟了界面,并显示提示信息。JS代码.Demo 可查看:http://wewoor.github.io/CNUI/document.html 。

//Alert
var Alert = { func : function(){},
name : "dialog",
show : function(msg){ //show function
var confirm = document.createElement("div");
confirm.className = this.name;
confirm.id = this.name;;
var confirmHeader = document.createElement("div");
confirmHeader.className = "dialog-header";
var headerSpan = document.createElement("span");
headerSpan.className = "dialog-title";
var confirmContent = document.createElement("div");
confirmContent.className = "dialog-content";
var contentSpan = document.createElement("span");
contentSpan.className = "content-main alert-content";
var contentBtnDiv = document.createElement("div");
contentBtnDiv.className="content-btn";
var btnConfirm = document.createElement("a"); //确认按钮
btnConfirm.href = "javascript:Alert.hide()";
btnConfirm.className = "btn alert"; //按钮添加
contentBtnDiv.appendChild(btnConfirm); confirmContent.appendChild(contentSpan);
confirmContent.appendChild(contentBtnDiv); confirmHeader.appendChild(headerSpan); confirm.appendChild(confirmHeader);
confirm.appendChild(confirmContent); //default button
headerSpan.innerHTML = "警示框!";
btnConfirm.innerHTML = "确认";
contentSpan.innerHTML = "这是一个警示框!";
if(msg != null && msg != undefined){
contentSpan.innerHTML = msg;
} document.body.appendChild(confirm);
return confirm;
},
hide : function(){
var confirm = document.getElementById(this.name);
if(confirm != null && confirm != undefined){
document.body.removeChild(confirm);
}
}
}

3.Confirm 组件

confirm对话框并没有像原生的confirm组件返回true 或者false,而是点击确认按钮后执行了传入的回调函数,点击取消按钮则移除了这个组件。demo请看:http://wewoor.github.io/CNUI/document.html

//Confirm
var Confirm = {
func : function(){},
name : "dialog",
show : function(msg,call){ //show function
var confirm = document.createElement("div");
confirm.className = this.name;
confirm.id = this.name;;
var confirmHeader = document.createElement("div");
confirmHeader.className = "dialog-header";
var headerSpan = document.createElement("span");
headerSpan.className = "dialog-title";
var confirmContent = document.createElement("div");
confirmContent.className = "dialog-content";
var contentSpan = document.createElement("span");
contentSpan.className = "content-main";
var contentBtnDiv = document.createElement("div");
contentBtnDiv.className="content-btn";
var btnConfirm = document.createElement("a"); //确认按钮
btnConfirm.href = "javascript:Confirm.callback()";
btnConfirm.className = "btn";
var btnCancle = document.createElement("a"); //取消按钮
btnCancle.className = "btn";
btnCancle.href = "javascript:Confirm.hide()"; //按钮添加
contentBtnDiv.appendChild(btnConfirm);
contentBtnDiv.appendChild(btnCancle); confirmContent.appendChild(contentSpan);
confirmContent.appendChild(contentBtnDiv); confirmHeader.appendChild(headerSpan); confirm.appendChild(confirmHeader);
confirm.appendChild(confirmContent); //default style
headerSpan.innerHTML = "对话框";
contentSpan.innerHTML = "这是确认对话框?";
btnConfirm.innerHTML = "确认";
btnCancle.innerHTML = "取消"; //if the property html is not null and not undefined
//just set this property.
if(msg != undefined){
contentSpan.innerHTML = msg;
} //set callback
if(call != null && call != undefined){
if(typeof(call) == "function"){
this.func = call;
}
} document.body.appendChild(confirm);
return confirm;
}, hide : function(){
var confirm = document.getElementById(this.name);
if(confirm != null && confirm != undefined){
document.body.removeChild(confirm);
}
},
callback : function(){
//执行call回调方法
this.func();
//隐藏confirm对象
this.hide();
}
}

最新文章

  1. PHP面向对象06_异常处理
  2. 关于CodeFirst异常:无法确定类型'XXX'和类型‘YYY’之间的关联的主体端,必须使用关系 Fluent API 或数据注释显式配置此关联的主体端。
  3. [转]揭秘webdriver实现原理
  4. UVALive 6124 Hexagon Perplexagon 题解
  5. wordpress the_date 方法 偶尔为空的问题
  6. 这是一个关于Latex的测试
  7. JS初学之-自定义属性(索引值)
  8. Windows7 32位机上,OpenCV中配置GPU操作步骤
  9. Nodejs.sublime-build 在sublime3中的配置
  10. 【C++小白成长撸】--N阶幻方(魔阵)矩阵
  11. 通过修改 LayoutInflater,全局替换字体!!!
  12. vue中的指令
  13. 你用.NET开发APP时,在云平台打包APP要填个“包名”的含义
  14. 转 Tomcat+redis+nginx配置
  15. 关于 spring MVC 配置自动扫描中 use-default-filters 属性
  16. EasyUI tabs指定要显示的tab
  17. 软件工程-pair work[附加题]
  18. 经典的GDB调试命令
  19. 定义get/set方法快捷方式
  20. Tornado的安装使用

热门文章

  1. Node.js(1)-helloworld
  2. Effective Java 67 Avoid excessive synchronization
  3. NHibernate使用ICriteria分页并返回数据库记录总条数
  4. HashMap与TreeMap的区别
  5. 大数据架构-使用HBase和Solr将存储与索引放在不同的机器上
  6. CSS纯样式实现箭头、对话框等形状
  7. 对Jena的简单理解和一个例子
  8. 关于统计变换(CT/MCT/RMCT)算法的学习和实现
  9. html跳转倒计时
  10. 【学习/研发】嵌入式Linux/Android开发有它就够了——迅为4412开发板