本篇的由来是群里面某个朋友提到说:有没有一个倒计时的特效,格式如分钟:秒;由此思考了下,觉得弄几个常用效果的js小插件还是不错的,可以供大家学习和使用,这里我取名为:shenniu.effect.js;希望大家喜欢,多多点赞支持:
. 时钟效果
. 倒计时
. 全选效果
. tab点击切换
. tab鼠标移动切换
. 文本输入搜索
. 几个常用table展示方式插件
. 列表插件shenniu.pager.js
下面一步一个脚印的来分享:
首先,先发个线上测试地址lovexins.com:8081/tpl/effect.html,接着需要引用jquery.js和shenniu.effect.js及shenniu.effect.css,然后咋们一起来看怎么使用和效果图
. 时钟插件代码:
//横向时钟 HenXiangClock: function (option) { var defOption = { id: "HenXiangClockId", format: "yyy-MM-dd HH:mm:ss", //格式 setInterNum: 1 * 1000, //js计时器的周期时间,默认1s }; $.extend(defOption, option); var clearVal = setInterval(function () { var dateTime = new Date(); var y = dateTime.getFullYear(); var M = dateTime.getMonth() + 1; var d = dateTime.getDate(); var h = dateTime.getHours(); var m = dateTime.getMinutes(); var s = dateTime.getSeconds(); var sy = y; var sM = addZero(M, 10, 0); var sd = addZero(d, 10, 0); var sh = addZero(h, 10, 0); var sm = addZero(m, 10, 0); var ss = addZero(s, 10, 0); var result = defOption.format. replace("yyyy", sy). replace("MM", sM). replace("dd", sd). replace("HH", sh). replace("mm", sm). replace("ss", ss); $("#" + option.id).html(result); if (defOption.setInterNum <= 0) { clearInterval(clearVal); } }, defOption.setInterNum); }
横向时钟
effect.HenXiangClock({ id: "div1_1", format: "yyyy-MM-dd HH:mm:ss" });
文字时钟
effect.HenXiangClock({ id: "div1_2", format: "yyyy年MM月dd日HH时mm分ss秒" });
缩写时钟
effect.HenXiangClock({ id: "div1_3", format: "HH时mm分ss秒" }); effect.HenXiangClock({ id: "div1_4", format: "HH:mm:ss" }); effect.HenXiangClock({ id: "div1_5", format: "yyyy-MM-dd", setInterNum: 0 });
. 倒计时插件代码:
//倒计时 ReClock: function (option) { var defOption = { id: "ReClockId", h: 0, //时 m: 0, //分钟 s: 0, //秒 format: "HH:mm:ss", //格式 isAutoZero: true, //数字个位数的时候,是否自动增加0 setInterNum: 1 * 1000, //js计时器的周期时间,默认1s backFun: function () { } }; $.extend(defOption, option); var clearVal = setInterval(function () { var dateTime = new Date(0, 0, 0, defOption.h, defOption.m, defOption.s, 0); if (defOption.s <= 0) { if (defOption.m <= 0) { if (defOption.h <= 0) { $("#" + defOption.id).html(""); //清除timer clearInterval(clearVal); //执行回调函数 defOption.backFun(); return; } else { defOption.s = 59; defOption.m = 59; defOption.h--; } } else { defOption.s = 59; defOption.m--; } } var h = dateTime.getHours(); var m = dateTime.getMinutes(); var s = dateTime.getSeconds(); var compareNum = defOption.isAutoZero &#63; 10 : 0; var sh = addZero(h, compareNum, 0); var sm = addZero(m, compareNum, 0); var ss = addZero(s, compareNum, 0); var result = defOption.format. replace("HH", sh). replace("mm", sm). replace("ss", ss); $("#" + defOption.id).html(result); defOption.s--; }, defOption.setInterNum); }
时钟倒计时
//倒计时 effect.ReClock({ id: "div2_1", m: 1, format: "mm:ss", backFun: function () { $("#div2_1").html("结束啦"); } });
提交按钮倒计时
$("#btn2_2").on("click", function () { var btnObj = $(this); btnObj.attr("disabled", "disabled") effect.ReClock({ id: "div2_2", s: 10, format: "ss秒后才能重新获取", isAutoZero: false, backFun: function () { btnObj.removeAttr("disabled"); } }); });
提交按钮倒计时缩写
$("#btn2_3").on("click", function () { var btnObj = $(this); btnObj.attr("disabled", "disabled") effect.ReClock({ id: "div2_3", s: 10, format: "ss秒", isAutoZero: false, backFun: function () { btnObj.removeAttr("disabled"); } }); });
. 全选插件代码:
//全选 CheckBoxAll: function (option) { var defOption = { nameAll: "cbAll", //全选项Name nameChild: "cb" //子项Name }; $.extend(defOption, option); $("input[type='checkbox'][name='" + defOption.nameAll + "']").on("click", function () { var isChecked = $(this).is(":checked"); $("input[type='checkbox'][name='" + defOption.nameChild + "']").prop("checked", isChecked); }); }
//全选 effect.CheckBoxAll({ nameAll: "cbAll", //全选项Name nameChild: "cb" //子项Name });
. tab切换插件:
//tab切换 TabPanel: function (option) { var defOption = { tabShowId: "tabShowId", //tab需要显示在div的Id data: [ { title: "tab1", content: "王小一", url: "" }, { title: "tab2", content: "", url: "http://121.42.208.152/" }, { title: "tab3", content: "王小二", url: "" }, { title: "tab4", content: "王小三", url: "" } ], isMouseMove: false, //是否鼠标移动切换 tabParentId: "divTab", //tab按钮父级的id tabContentId: "divTabContent" //内容区域父级Id }; $.extend(defOption, option); //构造html样式 var tHtml = []; var pHtml = []; $.each(defOption.data, function (i, item) { if (item.title.length > 0) { var labFirst = (i == 0 &#63; "class=\"checkLabel\"" : ""); var panelFirst = (i == 0 &#63; "" : "hide"); tHtml.push(''); if (item.content.length > 0) { var cOntent= item.content; pHtml.push('' + content + ''); } else if (item.url.length > 0) { pHtml.push(''); pHtml.push(' '); pHtml.push(''); } else { pHtml.push(''); } } }); if (tHtml.length <= 0) { return; } var tabHtml = []; tabHtml.push(''); tabHtml.push(tHtml.join('')); tabHtml.push(''); tabHtml.push(''); tabHtml.push(pHtml.join('')); tabHtml.push(''); $("#" + defOption.tabShowId).html(tabHtml.join('')); var tabParnetObj = $("#" + defOption.tabParentId); var tabCOntentObj= $("#" + defOption.tabContentId); tabParnetObj.find("label[data-panel-val]").on(defOption.isMouseMove &#63; "mouseover" : "click", function () { //对应值 var panelVal = $(this).attr("data-panel-val"); //tab按钮 tabParnetObj.find("label[data-panel-val]").removeClass("checkLabel"); $(this).addClass("checkLabel"); //必须div承载内容 tabContentObj.find("div[data-panel-item]").addClass("hide"); //全部隐藏 tabContentObj.find("div[data-panel-item='" + panelVal + "']").removeClass("hide"); //选中展示 }); }
tab点击切换
//tab点击切换 effect.TabPanel({ tabShowId: "divShowTab01", data: [ { title: "tab1", content: "最近的工作能力大大提升,
得到赏识,
可是太注重事业和赚钱了,
导致让身体透支,
需要多注意健康,
一日三餐要准时才好。", url: "" }, { title: "tab2", content: "今日身边的女性友人会是你的贵人,多跟她们接触会得到一些好消息。
另外财运旺盛,只要能抓紧契机,积极行动便能进账丰厚。", url: "" }, { title: "tab3", content: '很压抑。。。。', url: "" }, { title: "tab4", content: "", url: "http://121.42.208.152/" } ] });
tab鼠标移动切换
使用代码:
//tab滑动切换 effect.TabPanel({ tabShowId: "divShowTab02", data: [ { title: "tab1", content: "1
11
111
1111
11111
", url: "" }, { title: "tab2", content: "2
22
222
2222
22222
", url: "" }, { title: "tab3", content: "3
33
333
3333
33333
", url: "" } ], tabParentId: "divTab01", //tab按钮父级的id tabContentId: "divTabContent01", //内容区域父级Id isMouseMove: true });
. 文本输入搜索
//文本输入搜索 TxtSearch: function (option) { var defOption = { name: "txtSearch", //搜索框Name size: 5, //显示条数 data: [ { text: "我爱您啊", value: "1" }, { text: "我爱祖国", value: "2" }, { text: "我爱家人", value: "3" }, { text: "我喜欢美女", value: "4" }, { text: "我爱钱", value: "5" }, { text: "我是神牛步行3", value: "6" } ], showDivId: "div_TxtSearch" //展示内容的divId }; $.extend(defOption, option); $("input[name='" + defOption.name + "']").on("keyup", function () { var txtObj = $(this); var divSearchObj = txtObj.next("div[id='div_TxtSearch']"); if (divSearchObj) { divSearchObj.remove(); } var txtVal = $(this).val(); if (txtVal.length <= 0) { return; } var dataHtml = []; var nSize = 0; $.each(defOption.data, function (i, item) { if (item.text.indexOf(txtVal) >= 0) { dataHtml.push('
//文本下拉搜索 effect.TxtSearch({ name: "txtSearch", //搜索框Name size: 5,//显示5条 data: [ { text: "我爱您啊!", value: "1" }, { text: "我爱祖国!", value: "2" }, { text: "我爱家人!", value: "3" }, { text: "我喜欢美女!", value: "4" }, { text: "我爱钱!", value: "5" }, { text: "我是神牛步行3!", value: "6" } ] });
. 几个常用table展示方式插件table.shenniu.js
由于这个table.shenniu.js说明插件已经在前面文章分享过了,在里就不多说了各位可以点击链接看下使用说明
. 列表插件shenniu.pager.js
由于这个shenniu.pager.js说明件已经在前面文章分享过了,在里就不多说了各位可以点击链接看下使用说明
下面给出测试页面调用插件的例子,方便大家直接使用: