alert.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. $(function(){
  2. $(".back").click(function(){
  3. history.back();
  4. });
  5. load_size_com();
  6. window.onresize = function () {
  7. load_size_com();
  8. }
  9. });
  10. function load_size_com() {
  11. $(".top .title").css('left',($(window).width()-100)/2);
  12. }
  13. var remove_qq_alert = function(){
  14. $('.alertBox').add($('#mask')).remove();
  15. };
  16. window['alert'] = window['qq_alert'] = function(msg,loading){
  17. if($('.mask').length && loading){ //多次调用loading
  18. return 0;
  19. }
  20. remove_qq_alert();
  21. if(!loading){
  22. clearTimeout(window.alert.time);
  23. var obj = $('<div class="alertBox">' + msg + '</div>');
  24. $('body').append(obj);
  25. window.alert.time = setTimeout(function(){$(".alertBox").remove()},2000);
  26. }else{
  27. $(document.body).append($('<div class="alertBox"><div class="box_loading"><div class="loading_mask"></div></div>' + msg + '</div><div id="mask" class="mask"></div>'));
  28. $('.alertBox').css({"webkitAnimationName":"boxfade_loading","opacity":0.8});
  29. $('#mask').height(window.innerHeight + 'px');
  30. }
  31. };
  32. function back(){
  33. history.back();
  34. }
  35. var dateCONFIG={
  36. oneDay: 3600 * 24,
  37. oneMonth: 3600 * 24 * 30,
  38. oneYear: 3600 * 24 * 365
  39. };
  40. function calcTime(ts){
  41. var C = dateCONFIG,
  42. dur, t1 = new Date(),
  43. t2 = new Date();
  44. //t1.setTime(ts * 1000);
  45. t1=new Date(ts);
  46. dur = Math.ceil((t2.getTime() - t1.getTime()) / 1000);
  47. //return dur;
  48. if (dur > C.oneYear) {
  49. return Math.floor(dur / C.oneYear) + '年前';
  50. }
  51. else if (dur > C.oneMonth) {
  52. return Math.floor(dur / C.oneMonth) + '月前';
  53. }
  54. else if (dur > C.oneDay) {
  55. return Math.floor(dur / C.oneDay) + '天前';
  56. }
  57. else if (dur > 3600) {
  58. return Math.floor(dur / 3600) + '小时前';
  59. }
  60. else if (dur > 60) {
  61. return Math.floor(dur / 60) + '分钟前';
  62. }
  63. else {
  64. return dur + '秒前';
  65. }
  66. };
  67. //添加cookie
  68. function addCookie(objName, objValue, objHours) {//添加cookie
  69. var str = objName + "=" + escape(objValue);
  70. if (objHours > 0) {//为0时不设定过期时间,浏览器关闭时cookie自动消失
  71. var date = new Date();
  72. var ms = objHours * 3600 * 1000;
  73. date.setTime(date.getTime() + ms);
  74. str += "; expires=" + date.toGMTString();
  75. }
  76. document.cookie = str;
  77. }
  78. //获取cookie
  79. function getCookie(objName) {//获取指定名称的cookie的值
  80. var arrStr = document.cookie.split("; ");
  81. for (var i = 0; i < arrStr.length; i++) {
  82. var temp = arrStr[i].split("=");
  83. if (temp[0] == objName) return unescape(temp[1]);
  84. }
  85. }
  86. //删除cookie
  87. function delCookie(name) {//为了删除指定名称的cookie,可以将其过期时间设定为一个过去的时间
  88. var date = new Date();
  89. date.setTime(date.getTime() - 10000);
  90. document.cookie = name + "=a; expires=" + date.toGMTString();
  91. }