前不久在做一个彩票的项目时,有一个手动开奖的需求。所以有了这个倒计时按钮。下面分享下具体的代码:

效果:

代码:

App.directive('timerBtn', function() { // 倒计时按钮
return {
restrict: 'A',
replace: true,
scope: {
startTime: '=startTime',
getData: '&getData'
},
template: '<button class="btn btn-danger" style="border-radius: 30px;padding: 3px 16px;" ng-disabled="startTime> 0" ng-bind="startTime > 0 ? showTime + \' 后开奖\' : \'手动开奖\'" ng-click="getData()"></button>',
controller: function($scope, $interval) { var formatTime = function(second) {
return [parseInt(second / 60 / 60), parseInt(second / 60 % 60), second % 60].join(":")
.replace(/\b(\d)\b/g, "0$1");
} var timer = $interval(function() {
$scope.startTime -= 1;
$scope.showTime = formatTime($scope.startTime);
if($scope.startTime < 1) {
$interval.cancel(timer);
};
}, 1000); }
};
});

这个组件接受两个参数:

startTime:用于接收倒计时开始时间的时间戳
getData:用于接收倒计时结束之后触发的函数

用法:
<div timer-btn start-time="time" get-data="getData()"></div>
 
 

angularjs使用directive实现倒计时按钮的更多相关文章

  1. 前端angularJS利用directive实现移动端自定义软键盘的方法

    最近公司项目的需求上要求我们iPad项目上一些需要输入数字的地方用我们自定义的软键盘而不是移动端设备自带的键盘,刚接到需求有点懵,因为之前没有做过,后来理了一下思路发现这东西也就那样.先看一下实现之后 ...

  2. AngularJS之directive

    AngularJS之directive AngularJS是什么就不多舌了,这里简单介绍下directive.内容基本上是读书笔记,所以如果你看过<AngularJS up and runnin ...

  3. Angularjs之directive指令学习笔记(二)

    1.Directive的五个实例知道driective作用.其中字段restrict.template. replace.transclude.link用法 参考文章链接地址:http://damoq ...

  4. iOS 短信验证码倒计时按钮的实现

    验证码倒计时按钮的应用是非常普遍的,本文介绍了IOS实现验证码倒计时功能,点击获取验证码,进入时间倒计时,感兴趣的小伙伴们可以参考一下: 实现思路: 创建按钮,添加点击方法: 用NSTimer定时器, ...

  5. delphi倒计时按钮写法

    procedure TForm1.FormActivate(Sender: TObject); var i: Integer; begin btn8.Enabled:=False; do begin ...

  6. jquery倒计时按钮常用于验证码倒计时

    <!doctype html><html><head> <meta charset="utf-8"> <title>jq ...

  7. Angularjs的directive封装ztree

    一般我们做web开发都会用到树,恰好ztree为我们提供了多种风格的树插件. 接下来就看看怎么用Angularjs的directive封装ztree <!DOCTYPE html> < ...

  8. angularJS中directive父子组件的数据交互

    angularJS中directive父子组件的数据交互 1. 使用共享 scope 的时候,可以直接从父 scope 中共享属性.使用隔离 scope 的时候,无法从父 scope 中共享属性.在 ...

  9. React实战之60s倒计时按钮(发送短信验证按钮)

    React实战之60s倒计时按钮——短信验证按钮 导入:(antd组件——Form表单) import { Button, Form, Input } from 'antd'; const FormI ...

随机推荐

  1. 我的sublime常用快捷键

    sublime一般被应用于前端开发,在实际开发中,我们常用的sublime快捷键有哪些呢?这里汇总一下,常用的排在前面. 常用快捷键 Ctrl+Shift+P:打开命令面板 Ctrl+D:选择重复单词 ...

  2. 省队集训day6 B

    一道AC自动机题···· 一定要把一个节点没有的儿子接到它fai的儿子,否则会卡到n^2的······· #include<cstdio> #include<iostream> ...

  3. SQL主、外键,子查询

    主键 数据库主键是指表中一个列或列的组合,其值能唯一地标识表中的每一行.这样的一列或多列称为表的主键,通过它可强制表的实体完整性.当创建或更改表时可通过定义 PRIMARY KEY约束来创建主键.一个 ...

  4. 记 tower.im 的一次重构

    原文in here: http://outofmemory.cn/wr?u=http%3A%2F%2Fblog.mycolorway.com%2F2013%2F05%2F01%2Ftower-refa ...

  5. CentOS 6.x 下Postfix和dovecot邮件服务安装和基本配置

    1 卸载sendmail [root@mail~]# pstree | grep sendmail [root@mail~]# service sendmail stop [root@mail~]# ...

  6. mapreduce (二) MapReduce实现倒排索引(一) combiner是把同一个机器上的多个map的结果先聚合一次

    1 思路:0.txt MapReduce is simple1.txt MapReduce is powerfull is simple2.txt Hello MapReduce bye MapRed ...

  7. Xamarin Studio –Project not built in active configuration

    当我们加载项目以后如果出现以下项目提示 处理方式如下: 解决方案右键->options 配置->configuration mappings->勾选构建的ios项目 项目右键-> ...

  8. -_-#【JS】HTML5 API

    <JavaScript高级程序设计(第3版)> <!DOCTYPE html> <html> <head> <meta charset=" ...

  9. link@import

    1.两者区别 1)link属于XHTML标签,而@import是CSS提供的;2)页面被加载的时,link会同时被加载,而@import引用的CSS会等到页面被加载完再加载; 3)import只在IE ...

  10. Surrounded Regions——LeetCode

    Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'. A region is captured ...