插件比较简单,先来看DEMO吧,http://codepen.io/jonechen/pen/bZWdXq

CSS部分:

  1. *{margin:0;padding:0;font:14px/1.8 "Helvetica Neue","microsoft yahei";}
  2. ul,li{list-style:none;}
  3. body{background: #fff; }
  4. .checkin{margin: auto auto auto auto; }
  5. .clear {clear:both; height:0; overflow:hidden; display:block; line-height:0}
  6. .clearfix:after {clear:both;font-size:0; height:0; display:block; visibility:hidden; content:" "; line-height:0}
  7. .clearfix {zoom:1}/* for IE6 IE7 */
  8. .title{height: 36px;line-height: 36px;font-size: 16px;margin-bottom: 10px;}
  9. .title p{float: left;width: 80%;height: 36px;line-height: 36px;font-size: 16px;}
  10. .title a{display: inline-block;width: 20%;height: 36px;line-height: 36px;text-align: center;background: #42941a;border-radius: 5px;color: #fff;text-decoration: none;font-size: 16px;}
  11. .checkin li{background: #fee684; float: left;padding: 10px;text-align: center;}
  12. li.able-qiandao{background: #e9c530; }
  13. li.checked{background:#fee684 url(http://i2.piimg.com/508767/a9576b09fc014d6e.png) no-repeat center;}
  14. .mask{ width: 100%;height: 100%;position: absolute;top: 0;left: 0; background-color: rgba(0,0,0,0.55);visibility: hidden;transition: all 0.25s ease}
  15. .modal{background:#fff;width: 450px;height: 400px;border-radius: 10px;position: absolute;margin-top: -200px;margin-left:-225px;left: 50%;top: 50%;border:5px solid #42941a;box-sizing:border-box;overflow: hidden;transform: translateY(-200%);transition: all 0.25s ease}
  16. a.closeBtn{display: block;position: absolute;right: 10px;top: 5px;font-family: 'simsun';font-size: 18px;text-decoration: none;font-weight: bolder;color: #333}
  17. .title_h1{text-align: center;font-size: 40px;font-weight: normal;padding-top: 80px;display: block;width: 100%}
  18. .title_h1 span{display: inline-block;width: 40px;height: 40px;border-radius: 100%;background: #42941a;color: #fff;position: relative;float: left;margin-left: 30%;margin-top: 7px;}
  19. .title_h1 span::before{width: 10px;height: 2px;background: #fff;position: absolute;left: 8px;top: 23px;display: block;line-height: 0;font-size: 0;content: ""; transform: rotate(52deg);}
  20. .title_h1 span::after{width: 24px;height: 2px;background: #fff;position: absolute;left: 12px;top: 20px;display: block;line-height: 0;font-size: 0;content: "";transform: rotate(-45deg);}
  21. .title_h1 em{display: inline-block;font-size: 30px;float: left;margin-left: 10px;}
  22. .title_h1 i{display: inline-block;font-size: 16px;float: left;margin: 14px 0 0 10px;}
  23. .title_h2{text-align: center;font-size: 16px;display: block;padding-top: 20px;}
  24. .title_h2 span{font-size: 36px;color: #b25d06;}
  25. .trf{visibility: visible;}
  26. .trf .modal{transform: translateY(0);}

HTML部分:

  1. <div class="checkin"></div>
  2. <div class="mask">
  3. <div class="modal">
  4. <a href="#" class="closeBtn">×</a>
  5. <h1 class="title_h1 clearfix"><span></span><em>已签到</em> <i>您已签到2天</i></h1>
  6. <h2 class="title_h2">您获得现金<span>0.88元</span></h2>
  7. </div>
  8. </div>

JS插件部分:

  1. ;
  2. (function($) {
  3. var Checkin = function(ele, options) {
  4. this.ele = ele;
  5. this.opt = options;
  6. this.defaults = {
  7. width: 450,
  8. height: 'auto',
  9. background: '#f90',
  10. radius: 10,
  11. color: '#fff',
  12. padding: 10,
  13. dateArray: [1, 2, 4, 6], // 假设已签到的天数+1
  14. };
  15. this.obj = $.extend({}, this.defaults, this.opt);
  16. }
  17. Checkin.prototype.init = function() {
  18. var _self = this.ele,
  19. html = '',
  20. myDate = new Date(),
  21. year = myDate.getFullYear(),
  22. month = myDate.getMonth(),
  23. day = myDate.getDate(),
  24. weekText = ['日', '一', '二', '三', '四', '五', '六'];
  25. _self.css({
  26. width: this.obj.width + 'px',
  27. height: this.obj.height,
  28. background: this.obj.background,
  29. borderRadius: this.obj.radius,
  30. color: this.obj.color,
  31. padding: this.obj.padding
  32. }).append("<div class='title'><p>" + year + '年' + (month + 1) + '月' + day + '日' + "</p><a class=\'checkBtn\' href=\"javascript:;\">签到</a></div>");
  33. $("<ul class='week clearfix'></ul><ul class='calendarList clearfix'></ul>").appendTo(_self);
  34. for (var i = 0; i < 7; i++) {
  35. _self.find(".week").append("<li>" + weekText[i] + "</li>")
  36. };
  37. for (var i = 0; i < 42; i++) {
  38. html += "<li></li>"
  39. };
  40. _self.find(".calendarList").append(html);
  41. var $li = _self.find(".calendarList").find("li");
  42. _self.find(".week li").css({
  43. width: (_self.width() / 7) + 'px',
  44. height: 50 + 'px',
  45. borderRight: '1px solid #f90',
  46. boxSizing: 'border-box',
  47. background: '#b25d06'
  48. });
  49. $li.css({
  50. width: (_self.width() / 7) + 'px',
  51. height: 50 + 'px',
  52. borderRight: '1px solid #f90',
  53. borderBottom: '1px solid #f90',
  54. boxSizing: 'border-box',
  55. color: "#b25d06"
  56. });
  57. _self.find(".calendarList").find("li:nth-child(7n)").css('borderRight', 'none');
  58. _self.find(".week li:nth-child(7n)").css('borderRight', 'none');
  59. var monthFirst = new Date(year, month, 1).getDay();
  60. var d = new Date(year, (month + 1), 0)
  61. var totalDay = d.getDate(); //获取当前月的天数
  62. for (var i = 0; i < totalDay; i++) {
  63. $li.eq(i + monthFirst).html(i + 1);
  64. $li.eq(i + monthFirst).addClass('data' + (i + 1))
  65. if (isArray(this.obj.dateArray)) {
  66. for (var j = 0; j < this.obj.dateArray.length; j++) {
  67. if (i == this.obj.dateArray[j]) {
  68. // 假设已经签到的
  69. $li.eq(i + monthFirst).addClass('checked');
  70. }
  71. }
  72. }
  73. }
  74. //$li.eq(monthFirst+day-1).css('background','#f7ca8e')
  75. _self.find($(".data" + day)).addClass('able-qiandao');
  76. }
  77. var isChecked = false;
  78. Checkin.prototype.events = function() {
  79. var _self = this.ele;
  80. var $li = _self.find(".calendarList").find("li");
  81. $li.on('click', function(event) {
  82. event.preventDefault();
  83. /* Act on the event */
  84. if ($(this).hasClass('able-qiandao')) {
  85. $(this).addClass('checked');
  86. modal(_self);
  87. isChecked = true;
  88. }
  89. });
  90. var checkBtn = _self.find(".checkBtn");
  91. checkBtn.click(function(event) {
  92. modal(_self);
  93. _self.find('.able-qiandao').addClass('checked');
  94. isChecked = true;
  95. });
  96. }
  97. var modal = function(e) {
  98. var mask = e.parents().find(".mask");
  99. var close = e.parents().find(".closeBtn");
  100. if (mask && !isChecked) {
  101. mask.addClass('trf');
  102. } else {
  103. return
  104. };
  105. close.click(function(event) {
  106. event.preventDefault();
  107. mask.removeClass('trf')
  108. });
  109. e.parents().find('.checkBtn').text("已签到");
  110. }
  111. $.fn.Checkin = function(options) {
  112. var checkin = new Checkin(this, options);
  113. var obj = [checkin.init(), checkin.events()]
  114. return obj
  115. }
  116. var isArray = function(arg) {
  117. return Object.prototype.toString.call(arg) === '[object Array]';
  118. };
  119. })(jQuery);
  120. // 插件调用
  121. $(".checkin").Checkin();
  122. // 元素居中显示,与插件无关,根本自己需要修改;
  123. $(".checkin").css('marginTop',parseInt(($(window).innerHeight()-$(".checkin").outerHeight())/2)+'px');

jQuery日历签到插件的更多相关文章

  1. php+mysql+jquery日历签到

    在网站开发过程中我们会经常用到签到功能来奖励用户积分,或者做一些其他活动.这次项目开发过程中做了日历签到,因为没有经验所有走了很多弯路,再次记录过程和步骤. 1.日历签到样式: 2.本次签到只记录本月 ...

  2. jquery日历签到控件的实现

    calendar.js var calUtil = { //当前日历显示的年份 showYear:2015, //当前日历显示的月份 showMonth:1, //当前日历显示的天数 showDays ...

  3. 25个有用的jQuery日历和日期选取插件

    jQuery被认为是最好的JavaScript库,因为它简单易用.灵活,并有大量的插件.本文介绍25个非常不错的jQuery日历和日期选取插件,希望对各位有用. 1. Simple JQuery Da ...

  4. 11个实用jQuery日历插件

    1. FullCalendar FullCalendar是很出名的jQuery日历插件,它支持拖拽等功能,整合了Google Calendar,而且可以通过JSON来绑定事件,设计师可以轻松地自定义日 ...

  5. 10个漂亮的jQuery日历插件下载【转载】

    10个漂亮的jQuery日历插件下载 2013-08-07 标签:jQuery日历插件jQuery日历jQuery插件   日期是非常重要的,随时随地.微薄或网站的日期选取器日历必须在那里.您可以使用 ...

  6. 给开发者准备的 10 款最好的 jQuery 日历插件[转]

    这篇文章介绍的是 10 款最棒而且又很有用的 jQuery 日历插件,允许开发者们把这些漂亮的日历插件结合到自己的网站中.这些日历插件易用性都很强,轻轻松松的就可以把漂亮的日历插件装饰到你的网站了.希 ...

  7. 基于jQuery日历插件制作日历

    这篇文章主要介绍了基于jQuery日历插件制作日历的相关资料,需要的朋友可以参考下 来看下最终效果图吧: 是长得丑了一点,不要吐槽我-.- 首先来说说这个日历主要的制作逻辑吧: ·一个月份最多有31天 ...

  8. PHP实现日历签到,并实现累计积分功能

    在网站开发过程中我们会经常用到签到功能来奖励用户积分,或者做一些其他活动.这次项目开发过程中做了日历签到,因为没有经验所有走了很多弯路,再次记录过程和步骤. 1.日历签到样式:使用的是calendar ...

  9. 9款精致HTML5/jQuery日历时钟控件源码下载(源码请见百度云) 链接:http://pan.baidu.com/s/1geIXe75 密码:7m4a

    现在的网页应用越来越丰富,我们在网页中填写日期和时间已经再也不用手动输入了,而是使用各种各样的日期时间选择控件,大部分样式华丽的日期选择和日历控件都是基于jQuery和HTML5的,比如今天要分享的这 ...

随机推荐

  1. 20172330 2017-2018-1 《Java程序设计》第九周学习总结

    20172330 2017-2018-1 <程序设计与数据结构>第九周学习总结 教材学习内容总结 本周的学习包括两章内容,分别为异常和递归. 异常 错误和异常都是对象,代表非正常情况或者无 ...

  2. 软件工程课堂作业(五)——终极版随机产生四则运算题目(C++)

    一.升级要求:让程序能接受用户输入答案,并判定对错.最后给出总共对/错的数量. 二.设计思想: 1.首先输入答案并判断对错.我想到的是定义两个数组,一个存放用户算的结果,另一个存放正确答案.每输出一道 ...

  3. 深入理解Java对象序列化(转载)

    原文地址:http://developer.51cto.com/art/201202/317181.htm 1. 什么是Java对象序列化 Java平台允许我们在内存中创建可复用的Java对象,但一般 ...

  4. JavaScript数组自定义属性

    我们可以以json键值对的形式自定义属性. 首先定义一个JS数组JSarray. 然后按json键值对的形式进行赋值. 最后在控制台显示结果. 代码如下: var JSarray = new Arra ...

  5. 【Windows】Windows Restart Manager 重启管理器

    Restart Manager(以下简称RM)可以减少或避免安装或更新程序所需要的系统重启次数.安装(或更新)过程中需要重启的主要原因是需要更新的某些文件当前正被一些其它程序或服务所使用.RM允许除关 ...

  6. BZOJ 1834 网络扩容(最大流+费用流)

    对于第一问,直接求最大流. 对于第二问,建源点s和汇点t,s连1容量为INF,费用为0的边,n连t容量为最大流+k,费用为0的边.这样就把最大流限制为最多增加k了. 限制需要求扩充的最小费用,原图的边 ...

  7. javascript中检测一个变量的类型

    /** * 怎么检测一个变量的类型? * 在js中检测对象类型主要有三种:typeof, instanceof, constructor, 这几种都可以检测对象的类型. * 另外还可以适应jQuery ...

  8. CSS定义input disabled样式

    disabled 属性规定应该禁用 input 元素.被禁用的 input 元素既不可用,也不可点击.可以设置 disabled 属性,直到满足某些其他的条件为止(比如选择了一个复选框等等).然后,就 ...

  9. Python 源码剖析(四)【LIST对象】

    四.LIST对象 1.PyListObject对象 2.PyListObject的创建与维护 3.PyListObject 对象缓冲池 4.Hack PyListObject 1.PyListObje ...

  10. Linux相关——手写测试程序

    由于本人太弱,,,不会lemon,,,也不会在ubuntu下安装lemon,所以我选择手写测试程序emmmm 首先要写这个东西我们要先知道对拍怎么写. ; i <= ; i++) { syste ...