js简单倒计时
不想每次用倒计时,都现写代码,比较烦,这里记一下,也顺便分享一些倒计时简单的逻辑。
如果你有更简单方便的代码,可以分享给大家。
var method = {
countdownObj: {
timer: null,
changeTime: 0,
},
countdown: function(long, back) {
var that = this;
if (that.countdownObj.timer) {
clearInterval(that.countdownObj.timer);
}
that.countdownObj.changeTime = long;
back(that.countdownObj.changeTime);
that.countdownObj.timer = setInterval(function() {
that.countdownObj.changeTime--;
back(that.countdownObj.changeTime);
if (that.countdownObj.changeTime < 1) {
clearInterval(that.countdownObj.timer);
}
}, 1000);
}
};
method.countdown(60,function(time){
console.log(time);
});
函数里第一个数字是到时间长度,
第二个回调函数,回传的time就是当前时间。
勘误:
1018-12-12 修正了几个文字错误;优化了几个变量
原文地址:https://segmentfault.com/a/1190000017341822
js简单倒计时的更多相关文章
- js 简单倒计时插件和使用方法
// 倒计时插件 (function (){ function countdown(config){ var startDate = config.start ? new Date(config.st ...
- JS简单的倒计时(代码优化)
倒计时网上一大堆,所以也没有什么好说的,支持:1.年,月,日,天,时分秒等倒计时. JS代码如下: /* * js简单的倒计时 * @param {date,obj} 日期 对象格式 */ funct ...
- js实现倒计时60秒的简单代码
<!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Conten ...
- js 简单实现获取短信按钮倒计时60秒
<!DOCTYPE html><html lang="en"><head> <meta http-equiv="Content- ...
- 一个简单的js实现倒计时函数
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 倒计时的js实现 倒计时 js Jquery
by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.com/wordpress/?p=987 一.如火如荼的团 ...
- js时间倒计时
看了网上的其他的例子,觉得写的都有点复杂,不好理解,于是自己动手写了个. 本来想封装成jquery插件,但是觉得因为功能很简单,没有必要做成jquery插件,引用的时候不需要引入jqery库,这里直接 ...
- js简单 图片版时钟,带翻转效果
js简单 图片版时钟,带翻转效果 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"& ...
- jQuery简单倒计时插件
一. 效果预览 二. 实现 1. 按照特定的类结构布局. 2. 需要先引入jQuery,再引入此文件. /** * Author: CC11001100 * * 简单倒计时 * * 1. 支持页面内同 ...
随机推荐
- centos 安装系列
装coreseek https://www.jb51.net/os/RedHat/462185.html 卸载mysql https://www.cnblogs.com/cyl048/p/687908 ...
- java.sql.SQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails
HTTP Status 500 - Request processing failed; nested exception is org.hibernate.exception.ConstraintV ...
- 用惯了jquery, 想用angularjs 还真不好理解
jquery 比较直白,什么都是操作dom 节点. angularjs 就好比 thinkphp, ci 等框架,有自己约定的格式和方式.需要遵循它的规则,研究中... 比如说我,用了很长事件的jqu ...
- MySQL 普通注册插入优化。
普通做法是: 用户通过手机号注册.默认是根据这个手机号去用户表里查询,看有没有这个手机号,有那么就提示已注册.否则就执行注册插入数据库操作.这里其实正常注册流程是两次数据库操作的(查询,插入): 优化 ...
- linux下定位文件
参考:http://www.cnblogs.com/ccode/p/4033088.html: 在linux命令行模式下,经常会遇到定位文件的问题,这时候采用locate和find都是可以的,下面简述 ...
- 浏览器在IE8 以下时显示提示信息,提示用户升级浏览器
<!--[if lt IE 8]> <div style="background: #eeeeee;border-bottom: 1px solid #cccccc;col ...
- zeroclipboard复制插件兼容IE8
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- light7结合jquery实现开关按钮
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...
- SSH 框架controller向jsp传递List jsp中使用el表达式获取
mvc可以使用ModelAndViev传递数据选择跳转的视图 controller中的代码, 把一个模拟的表单studentListSimulate传给ModelAndView @RequestMap ...
- WordPress资料收集,以后整理
WordPress主题开发:实现分页功能 http://www.cnblogs.com/tinyphp/p/6361901.html WordPress如何调取显示指定文章 https://www.d ...