jQuery日历签到插件
插件比较简单,先来看DEMO吧,http://codepen.io/jonechen/pen/bZWdXq;
CSS部分:
*{margin:0;padding:0;font:14px/1.8 "Helvetica Neue","microsoft yahei";}
ul,li{list-style:none;}
body{background: #fff; }
.checkin{margin: auto auto auto auto; }
.clear {clear:both; height:0; overflow:hidden; display:block; line-height:0}
.clearfix:after {clear:both;font-size:0; height:0; display:block; visibility:hidden; content:" "; line-height:0}
.clearfix {zoom:1}/* for IE6 IE7 */
.title{height: 36px;line-height: 36px;font-size: 16px;margin-bottom: 10px;}
.title p{float: left;width: 80%;height: 36px;line-height: 36px;font-size: 16px;}
.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;}
.checkin li{background: #fee684; float: left;padding: 10px;text-align: center;}
li.able-qiandao{background: #e9c530; }
li.checked{background:#fee684 url(http://i2.piimg.com/508767/a9576b09fc014d6e.png) no-repeat center;}
.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}
.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}
a.closeBtn{display: block;position: absolute;right: 10px;top: 5px;font-family: 'simsun';font-size: 18px;text-decoration: none;font-weight: bolder;color: #333}
.title_h1{text-align: center;font-size: 40px;font-weight: normal;padding-top: 80px;display: block;width: 100%}
.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;}
.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);}
.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);}
.title_h1 em{display: inline-block;font-size: 30px;float: left;margin-left: 10px;}
.title_h1 i{display: inline-block;font-size: 16px;float: left;margin: 14px 0 0 10px;}
.title_h2{text-align: center;font-size: 16px;display: block;padding-top: 20px;}
.title_h2 span{font-size: 36px;color: #b25d06;}
.trf{visibility: visible;}
.trf .modal{transform: translateY(0);}
HTML部分:
<div class="checkin"></div>
<div class="mask">
<div class="modal">
<a href="#" class="closeBtn">×</a>
<h1 class="title_h1 clearfix"><span></span><em>已签到</em> <i>您已签到2天</i></h1>
<h2 class="title_h2">您获得现金<span>0.88元</span></h2>
</div>
</div>
JS插件部分:
;
(function($) {
var Checkin = function(ele, options) {
this.ele = ele;
this.opt = options;
this.defaults = {
width: 450,
height: 'auto',
background: '#f90',
radius: 10,
color: '#fff',
padding: 10,
dateArray: [1, 2, 4, 6], // 假设已签到的天数+1
};
this.obj = $.extend({}, this.defaults, this.opt);
}
Checkin.prototype.init = function() {
var _self = this.ele,
html = '',
myDate = new Date(),
year = myDate.getFullYear(),
month = myDate.getMonth(),
day = myDate.getDate(),
weekText = ['日', '一', '二', '三', '四', '五', '六'];
_self.css({
width: this.obj.width + 'px',
height: this.obj.height,
background: this.obj.background,
borderRadius: this.obj.radius,
color: this.obj.color,
padding: this.obj.padding
}).append("<div class='title'><p>" + year + '年' + (month + 1) + '月' + day + '日' + "</p><a class=\'checkBtn\' href=\"javascript:;\">签到</a></div>");
$("<ul class='week clearfix'></ul><ul class='calendarList clearfix'></ul>").appendTo(_self);
for (var i = 0; i < 7; i++) {
_self.find(".week").append("<li>" + weekText[i] + "</li>")
};
for (var i = 0; i < 42; i++) {
html += "<li></li>"
};
_self.find(".calendarList").append(html);
var $li = _self.find(".calendarList").find("li");
_self.find(".week li").css({
width: (_self.width() / 7) + 'px',
height: 50 + 'px',
borderRight: '1px solid #f90',
boxSizing: 'border-box',
background: '#b25d06'
});
$li.css({
width: (_self.width() / 7) + 'px',
height: 50 + 'px',
borderRight: '1px solid #f90',
borderBottom: '1px solid #f90',
boxSizing: 'border-box',
color: "#b25d06"
});
_self.find(".calendarList").find("li:nth-child(7n)").css('borderRight', 'none');
_self.find(".week li:nth-child(7n)").css('borderRight', 'none');
var monthFirst = new Date(year, month, 1).getDay();
var d = new Date(year, (month + 1), 0)
var totalDay = d.getDate(); //获取当前月的天数
for (var i = 0; i < totalDay; i++) {
$li.eq(i + monthFirst).html(i + 1);
$li.eq(i + monthFirst).addClass('data' + (i + 1))
if (isArray(this.obj.dateArray)) {
for (var j = 0; j < this.obj.dateArray.length; j++) {
if (i == this.obj.dateArray[j]) {
// 假设已经签到的
$li.eq(i + monthFirst).addClass('checked');
}
}
}
}
//$li.eq(monthFirst+day-1).css('background','#f7ca8e')
_self.find($(".data" + day)).addClass('able-qiandao');
}
var isChecked = false;
Checkin.prototype.events = function() {
var _self = this.ele;
var $li = _self.find(".calendarList").find("li");
$li.on('click', function(event) {
event.preventDefault();
/* Act on the event */
if ($(this).hasClass('able-qiandao')) {
$(this).addClass('checked');
modal(_self);
isChecked = true;
}
});
var checkBtn = _self.find(".checkBtn");
checkBtn.click(function(event) {
modal(_self);
_self.find('.able-qiandao').addClass('checked');
isChecked = true;
});
}
var modal = function(e) {
var mask = e.parents().find(".mask");
var close = e.parents().find(".closeBtn");
if (mask && !isChecked) {
mask.addClass('trf');
} else {
return
};
close.click(function(event) {
event.preventDefault();
mask.removeClass('trf')
});
e.parents().find('.checkBtn').text("已签到");
}
$.fn.Checkin = function(options) {
var checkin = new Checkin(this, options);
var obj = [checkin.init(), checkin.events()]
return obj
}
var isArray = function(arg) {
return Object.prototype.toString.call(arg) === '[object Array]';
};
})(jQuery);
// 插件调用
$(".checkin").Checkin();
// 元素居中显示,与插件无关,根本自己需要修改;
$(".checkin").css('marginTop',parseInt(($(window).innerHeight()-$(".checkin").outerHeight())/2)+'px');
jQuery日历签到插件的更多相关文章
- php+mysql+jquery日历签到
在网站开发过程中我们会经常用到签到功能来奖励用户积分,或者做一些其他活动.这次项目开发过程中做了日历签到,因为没有经验所有走了很多弯路,再次记录过程和步骤. 1.日历签到样式: 2.本次签到只记录本月 ...
- jquery日历签到控件的实现
calendar.js var calUtil = { //当前日历显示的年份 showYear:2015, //当前日历显示的月份 showMonth:1, //当前日历显示的天数 showDays ...
- 25个有用的jQuery日历和日期选取插件
jQuery被认为是最好的JavaScript库,因为它简单易用.灵活,并有大量的插件.本文介绍25个非常不错的jQuery日历和日期选取插件,希望对各位有用. 1. Simple JQuery Da ...
- 11个实用jQuery日历插件
1. FullCalendar FullCalendar是很出名的jQuery日历插件,它支持拖拽等功能,整合了Google Calendar,而且可以通过JSON来绑定事件,设计师可以轻松地自定义日 ...
- 10个漂亮的jQuery日历插件下载【转载】
10个漂亮的jQuery日历插件下载 2013-08-07 标签:jQuery日历插件jQuery日历jQuery插件 日期是非常重要的,随时随地.微薄或网站的日期选取器日历必须在那里.您可以使用 ...
- 给开发者准备的 10 款最好的 jQuery 日历插件[转]
这篇文章介绍的是 10 款最棒而且又很有用的 jQuery 日历插件,允许开发者们把这些漂亮的日历插件结合到自己的网站中.这些日历插件易用性都很强,轻轻松松的就可以把漂亮的日历插件装饰到你的网站了.希 ...
- 基于jQuery日历插件制作日历
这篇文章主要介绍了基于jQuery日历插件制作日历的相关资料,需要的朋友可以参考下 来看下最终效果图吧: 是长得丑了一点,不要吐槽我-.- 首先来说说这个日历主要的制作逻辑吧: ·一个月份最多有31天 ...
- PHP实现日历签到,并实现累计积分功能
在网站开发过程中我们会经常用到签到功能来奖励用户积分,或者做一些其他活动.这次项目开发过程中做了日历签到,因为没有经验所有走了很多弯路,再次记录过程和步骤. 1.日历签到样式:使用的是calendar ...
- 9款精致HTML5/jQuery日历时钟控件源码下载(源码请见百度云) 链接:http://pan.baidu.com/s/1geIXe75 密码:7m4a
现在的网页应用越来越丰富,我们在网页中填写日期和时间已经再也不用手动输入了,而是使用各种各样的日期时间选择控件,大部分样式华丽的日期选择和日历控件都是基于jQuery和HTML5的,比如今天要分享的这 ...
随机推荐
- java---Map接口实现类
Map是一个双列集合接口,如果实现了Map接口,特点是数据以键值对形式存在,键不可重复,值可以重复.java中主要有HashMap.TreeMap.Hashtable.本文主要介绍Map的接口方法: ...
- LintCode-365.二进制中有多少个1
二进制中有多少个1 计算在一个 32 位的整数的二进制表式中有多少个 1. 样例 给定 32 (100000),返回 1 给定 5 (101),返回 2 给定 1023 (111111111),返回 ...
- iOS开发UIApplication用法
1.简单介绍 (1)UIApplication对象是应用程序的象征,一个UIApplication对象就代表一个应用程序. (2)每一个应用都有自己的UIApplication对象,而且是单例的,如果 ...
- Linux文件传输FTP详解
ftp命令用来设置文件系统相关功能.ftp服务器在网上较为常见,Linux ftp命令的功能是用命令的方式来控制在本地机和远程机之间传送文件,这里详细介绍Linux ftp命令的一些经常使用的命令,相 ...
- BER-TLV数据结构
本文是自身在研究学习过程中碰到的问题,整理而成. 为了便于后文的引用说明,先列出一段TLV结构的数据: [6F] 4D │ ├─[] A0000003330101 │ ├─[A5] │ │ ├─[] ...
- 从一个简单的main方法执行谈谈JVM工作机制
本来JVM的工作原理浅到可以泛泛而谈,但如果真的想把JVM工作机制弄清楚,实在是很难,涉及到的知识领域太多.所以,本文通过简单的mian方法执行,浅谈JVM工作原理,看看JVM里面都发生了什么. 先上 ...
- bsxfun函数
函数功能:两个数组间元素逐个计算的二值操作 使用方法:C=bsxfun(fun,A,B) 两个数组A合B间元素逐个计算的二值操作,fun是函数句柄或者m文件,也可以为如下内置函数: @plus 加@m ...
- C++中Map的使用 (个人简单的对于String的使用)
#include<map> #include<iostream> #include<string> using namespace std; int main() ...
- 【题解】HNOI2004敲砖块
题目传送门:洛谷1437 决定要养成随手记录做过的题目的好习惯呀- 这道题目乍看起来和数字三角形有一点像,但是仔细分析就会发现,因为选定一个数所需要的条件和另一个数所需要的条件会有重复的部分,所以状态 ...
- 1040: [ZJOI2008]骑士
首先是因为想学仙人掌图才来先拿这题热热身,结果&……竟然调了一个晚上我的傻叉!(其中一大半的时候是在郁闷hzwer和Greens的代码画风不一样,后来才发现一个用拓扑一个用树dp23333,以 ...