portal html css js resource

jquery.similar.msgbox.js 4.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. (function () {
  2. $.MsgBox = {
  3. Alert: function (title, msg) {
  4. GenerateHtml("alert", title, msg);
  5. btnOk(); //alert只是弹出消息,因此没必要用到回调函数callback
  6. btnNo();
  7. },
  8. Confirm: function (title, msg, callback) {
  9. GenerateHtml("confirm", title, msg);
  10. btnOk(callback);
  11. btnNo();
  12. }
  13. }
  14. //生成Html
  15. var GenerateHtml = function (type, title, msg) {
  16. var _html = "";
  17. _html += '<div id="mb_box"></div><div id="mb_con"><span id="mb_tit">' + title + '</span>';
  18. _html += '<a id="mb_ico"></a><div id="mb_msg">' + msg + '</div><div id="mb_btnbox">';
  19. if (type == "alert") {
  20. _html += '<input id="mb_btn_ok" type="button" value="确定" />';
  21. }
  22. if (type == "confirm") {
  23. _html += '<input id="mb_btn_ok" type="button" value="确定" />';
  24. _html += '<input id="mb_btn_no" type="button" value="取消" />';
  25. }
  26. _html += '</div></div>';
  27. //必须先将_html添加到body,再设置Css样式
  28. $("body").append(_html); GenerateCss();
  29. }
  30. //生成Css
  31. var GenerateCss = function () {
  32. $("#mb_box").css({ width: '100%', height: '100%', zIndex: '99999', position: 'fixed',
  33. filter: 'Alpha(opacity=60)', backgroundColor: 'black', top: '0', left: '0', opacity: '0.3'
  34. });
  35. $("#mb_con").css({ zIndex: '999999', width: '400px', position: 'fixed',
  36. backgroundColor: 'White', borderRadius: '10px',boxShadow:' 0px 1px 8px #9f9d9d'
  37. });
  38. $("#mb_tit").css({ display: 'block', fontSize: '14px', color: 'rgb(150, 150, 150)', padding: '10px 15px',
  39. backgroundColor: '#fff', borderRadius: '10px 10px 0 0', marginTop: '4px',
  40. borderBottom: '2px solid #ff9900', fontWeight: 'bold',fontFamily: 'Microsoft Yahei,Hiragino Sans GB, PingFang SC,Helvetica Neue,WenQuanYi Micro Hei,sans-serif'
  41. });
  42. $("#mb_msg").css({ padding: '20px', lineHeight: '20px',
  43. borderBottom: '1px dashed #DDD',wordBreak:'break-all', textAlign:'justify', fontSize: '14px',fontFamily: 'Microsoft Yahei,Hiragino Sans GB, PingFang SC,Helvetica Neue,WenQuanYi Micro Hei,sans-serif'
  44. });
  45. $("#mb_ico").css({ display: 'block', position: 'absolute', right: '-35px', top: '8px',
  46. background:'url(../images/workclose.png) center center no-repeat', width: '24px', height: '24px',cursor: 'pointer'
  47. });
  48. $("#mb_btnbox").css({ margin: '16px 10px 20px 10px', textAlign: 'center', position:'relative' });
  49. $("#mb_btn_ok,#mb_btn_no").css({ width: '84px', fontSize: '14px', height: '30px', color: 'white', border: 'none' });
  50. $("#mb_btn_ok").css({backgroundImage:'none', padding:'0',margin:'0', backgroundColor: '#ff9900',borderRadius: '6px',fontFamily: 'Microsoft Yahei,Hiragino Sans GB, PingFang SC,Helvetica Neue,WenQuanYi Micro Hei,sans-serif'});
  51. $("#mb_btn_no").css({backgroundImage:'none', padding:'0',margin:'0', backgroundColor: 'gray', marginLeft: '20px',borderRadius: '6px',fontFamily: 'Microsoft Yahei,Hiragino Sans GB, PingFang SC,Helvetica Neue,WenQuanYi Micro Hei,sans-serif' });
  52. //右上角关闭按钮hover样式
  53. // $("#mb_ico").hover(function () {
  54. // $(this).css({ backgroundColor: '#ff9900', color: 'White',border:'1px solid #ff9900' });
  55. // }, function () {
  56. // $(this).css({ backgroundColor: '#DDD', color: '#666',border:'1px solid #666' });
  57. // });
  58. var _widht = document.documentElement.clientWidth; //屏幕宽
  59. var _height = document.documentElement.clientHeight; //屏幕高
  60. var boxWidth = $("#mb_con").width();
  61. var boxHeight = $("#mb_con").height();
  62. //让提示框居中
  63. $("#mb_con").css({ top: (_height - boxHeight) / 2 + "px", left: (_widht - boxWidth) / 2 + "px" });
  64. }
  65. //确定按钮事件
  66. var btnOk = function (callback) {
  67. $("#mb_btn_ok").click(function () {
  68. $("#mb_box,#mb_con").remove();
  69. if (typeof (callback) == 'function') {
  70. callback();
  71. }
  72. });
  73. }
  74. //取消按钮事件
  75. var btnNo = function () {
  76. $("#mb_btn_no,#mb_ico").click(function () {
  77. $("#mb_box,#mb_con").remove();
  78. });
  79. }
  80. })();