jq数字翻页效果,随机数字显示,实现上下翻动效果
最近在做一个项目,需要实时展示一串数字,要有类似于日历翻页的效果,在网上找寻了一番,发现dataStatistics这个插件http://www.jq22.com/jquery-info8141能实现这种效果,但是它实现的是在min设置的数值上累加1,css样式效果满足,但不符合的需要实时展示任意的数字要求,于是就稍微改动了一下代码,下面是项目代码。前端新手,代码写的很粗糙。
css样式部分
<style>
.dataStatistics .digit_set {
float: left;
border-radius: 10px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
border: 1px solid #111111;
width: 60px;
height: 100%;
display: inline-block;
position: relative;
margin: 0 5px;
}
.dataStatistics .digit {
position: absolute;
height: 100%;
}
.dataStatistics {
color: #fedec2;
font-family: "Helvetica Neue", Helvetica, sans-serif;
font-size: 90px;
font-weight: bold;
line-height: 80px;
height: 80px;
width: 746px;
margin: 0px auto;
}
.dataStatistics .digit > div {
position: absolute;
left: 0;
overflow: hidden;
height: 50%;
width: 50px;
padding: 0 5px;
-webkit-box-sizing: content-box;
-moz-box-sizing: content-box;
/* box-sizing: border-box; */
}
.dataStatistics .digit > div.digit_top:before, .dataStatistics .digit > div.shadow_top:before {
content: "";
height: 100%;
width: 100%;
position: absolute;
left: 0;
top: 0;
}
.dataStatistics .digit > div.digit_top, .dataStatistics .digit > div.shadow_top {
width: 60px;
background-color: #e38538;
border-bottom: 1px solid #e38538;
box-sizing: border-box;
top: 0;
/*z-index: 0;*/
border-radius: 10px 10px 0 0;
}
.digit_wrap {
line-height: 80px;
display: block;
overflow: hidden;
}
.dataStatistics .digit.active .digit_top {
z-index: 1;
display: none;
}
.dataStatistics .digit > div.digit_bottom, .dataStatistics .digit > div.shadow_bottom {
background-color: #e38538;
bottom: 0;
z-index: 0;
border-radius: 0 0 10px 10px;
}
.dataStatistics .digit > div.digit_bottom .digit_wrap, .dataStatistics .digit > div.shadow_bottom .digit_wrap {
display: block;
margin-top: -78%;
}
/*.digit_bottom {
-webkit-transform-origin: 0% 50%;
-webkit-animation: flipBottom 3s 0.3s ease-out both;
-moz-transform-origin: 0% 50%;
-moz-animation: flipBottom 3s 0.3s ease-out both;
-ms-transform-origin: 0% 50%;
-ms-animation: flipBottom 3s 0.3s ease-out both;
transform-origin: 0% 50%;
animation: flipBottom 3s 0.3s ease-out both;
}*/
.dataStatistics .digit.active .digit_bottom {
z-index: 2;
-webkit-transform-origin: 50% 0%;
-webkit-animation: flipBottom 0.3s 0.3s ease-out both;
-moz-transform-origin: 50% 0%;
-moz-animation: flipBottom 0.3s 0.3s ease-out both;
-ms-transform-origin: 50% 0%;
-ms-animation: flipBottom 0.3s 0.3s ease-out both;
transform-origin: 50% 0%;
animation: flipBottom 0.3s 0.3s ease-out both;
}
.dataStatistics .digit.activeup .digit_top {
z-index: 2;
-webkit-transform-origin: 0% 100%;
-webkit-animation: flipBottomup 0.3s 0.3s ease-out both;
-moz-transform-origin: 0% 100%;
-moz-animation: flipBottomup 0.3s 0.3s ease-out both;
-ms-transform-origin: 0% 100%;
-ms-animation: flipBottomup 0.3s 0.3s ease-out both;
transform-origin: 0% 100%;
animation: flipBottomup 0.3s 0.3s ease-out both;
}
@keyframes flipBottom {
0% {
-webkit-transform: perspective(400px) rotateX(90deg); }
100% {
-webkit-transform: perspective(400px) rotateX(0deg); }
}
@keyframes flipBottomup {
0% {
-webkit-transform: perspective(400px) rotateX(-90deg); }
100% {
-webkit-transform: perspective(400px) rotateX(0deg); }
}
/*@keyframes flipBottom1 {
0% {
-webkit-transform: perspective(400px) rotateX(-90deg); }
100% {
-webkit-transform: perspective(400px) rotateX(0deg); }
}*/
.dataStatistics .digit.activeup .digit_bottom{
z-index: 1;
display: none;
}
</style>
html代码
<div class="dataStatistics">
<div class="digit_set"></div>
<div class="digit_set"></div>
<div class="digit_set"></div>
<div class="digit_set"></div>
<div class="digit_set"></div>
<div class="digit_set"></div>
</div>
<script src="http://libs.baidu.com/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.dataStatistics.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('.dataStatistics').dataStatistics({min:4251,times:3000,len:6});
});
</script>
javascript代码jquery.dataStatistics.js文件,由于是模仿任意数字显示滚动效果,就设置了0-9之内的随机数,3秒钟执行了一次累加,真实项目中是需要从后台获取任意数字然后再赋值。
$.fn.dataStatistics = function(options){
options = $.extend({
min : 100, //初始数值
times: 3000,
len:9 //数字是几位数
},options || {});
var ths = this;//解决this指向问题
//初始化---------------------------------------start
var el = ths.find('.set_last');
var html = '<div class="digit">' +
' <div class="digit_top">' +
' <span class="digit_wrap"></span>' +
' </div>' +
' <div class="shadow_top"></div>' +
' <div class="digit_bottom">' +
' <span class="digit_wrap"></span>' +
' </div>' +
' <div class="shadow_bottom"></div>' +
'</div>'
//初始化值
var nowNums=zfill(options.min, options.len).split("");
var realcarNums=options.min;
console.log(nowNums)
//补0
function zfill(num, size) {
var s = "000000000" + num;
return s.substr(s.length-size);//字符串从7开始取得字符串
}
ths.find('.digit_set').each(function() {
for(i=0; i<=9; i++) {
$(this).append(html);
$(this).find('.digit').eq(i).find('.digit_wrap').append(i);//每一个位数添加对应的数字
}
});
//初始化数值填入
$.each(nowNums, function(index,val) {//nowNums为一个数组[0,0,4,2,5,0]
var set =ths.find('.digit_set').eq(index);
var i =parseInt(val)
// console.log(i)
set.find('.digit').eq(i).addClass('active');
set.find('.digit').eq(i).find(".digit_top").slideDown(300)
// set.find('.digit').eq(i+1).addClass('previous');
});
//初始化---------------------------------------end
var oldcarNums=nowNums,nowarrcar=[];//旧数组为空值,新数组为添加了元素的值
function run(){
var nowrealcarNums=0;
function increase() {
var carnum=Math.floor(Math.random()*10)//0-9以内的随机数
nowrealcarNums=realcarNums+carnum;
console.log(nowrealcarNums)
realcarNums=nowrealcarNums
nowarrcar=zfill(nowrealcarNums, options.len).toString().split("")//添加了数量的新数组
$.each(nowarrcar, function(index,val) {
var set =ths.find('.digit_set').eq(index);
var i =parseInt(val)
if(nowarrcar[index]>oldcarNums[index]){
set.find('.digit').removeClass('active')
set.find('.digit').removeClass('activeup')
set.find('.digit').eq(i).addClass("active")
set.find('.digit').eq(i).find(".digit_top").fadeIn(500)
}
if(nowarrcar[index]<oldcarNums[index]){
set.find('.digit').removeClass('active')
set.find('.digit').removeClass('activeup')
set.find('.digit').eq(i).addClass("activeup")
console.log(123)
set.find('.digit').eq(i).find(".digit_bottom").fadeIn(500)
}
})
oldcarNums=nowarrcar
}
var timer1 = setInterval(increase,options.times);
}
run();
};
这个是最终效果
jq数字翻页效果,随机数字显示,实现上下翻动效果的更多相关文章
- [Qt] CFlip 翻页功能实现
由于需要给table制作翻页功能,所以写了一个翻页的类. 看上去总体效果感觉还是不错的,哈哈. //flip.h #ifndef CFLIP_H #define CFLIP_H #include &l ...
- transform3D实现翻页效果
---恢复内容开始--- 闲篇 最近升级了下百度音乐,唯一的感觉就是动画效果很炫丽.我不是个对产品很敏感的人,但是这段时间观察一些大厂的产品发现现在的APP越来越重视动画效果了.大家可能没有注意过,连 ...
- Qt仿Android带特效的数字时钟源码分析(滑动,翻页,旋转效果)
这个数字时钟的源码可以在Qt Demo中找到,风格是仿Android的,不过该Demo中含有三种动画效果(鉴于本人未曾用过Android的系统,因此不知道Android的数字时钟是否也含有这三种效果) ...
- vue案例 - vue-awesome-swiper实现h5滑动翻页效果
说到h5的翻页,很定第一时间想到的是swiper.但是我当时想到的却是,vue里边怎么用swiper?! 中国有句古话叫:天塌下来有个高的顶着. 在前端圈里,总有前仆后继的仁人志士相继挥洒着热汗(这里 ...
- 基于vue实现上下滑动翻页效果
18年年底的时候,一直在做年度报告的H5页面,因为项目需要,需要实现上下滑动翻页,并且上滑的页面比正常页面的比例要缩小一定比例. 效果类似于http://www.17sucai.com/pins/de ...
- 微信里经常看到的滑动翻页效果,slide
上个星期我们的产品姐姐让我帮她写个微信里经常看到的滑动翻页效果,今天抽空写了3个小demo(只写了webkit需要chrome模拟手机看 开启touch事件), 故此写个随笔. 1.demo1,整个大 ...
- 转载 vue-awesome-swiper - 基于vue实现h5滑动翻页效果
说到h5的翻页,很定第一时间想到的是swiper.但是我当时想到的却是,vue里边怎么用swiper?! 中国有句古话叫:天塌下来有个高的顶着. 在前端圈里,总有前仆后继的仁人志士相继挥洒着热汗(这里 ...
- webapp应用--模拟电子书翻页效果
前言: 现在移动互联网发展火热,手机上网的用户越来越多,甚至大有超过pc访问的趋势.所以,用web程序做出仿原生效果的移动应用,也变得越来越流行了.这种程序也就是我们常说的单页应用程序,它也有一个英文 ...
- jquery css3问卷答题卡翻页动画效果
这个选项调查的特效以选项卡的形式,每答完一道题目自动切换到下一条,颇具特色.使用jQuery和CSS3,适合HTML5浏览器. 效果展示 http://hovertree.com/texiao/jqu ...
随机推荐
- C# 使用Environment获取当前程序运行环境相关信息
Enviroment类和AppDomain类前者表示系统级的相关信息,后者表示应用程序级的相关信息. 我常用这两个类获取一些程序运行目录.操作系统位数等信息: string basedir = App ...
- Python【day 11】闭包
闭包 1.闭包的概念: 嵌套函数中,父级函数的变量,在子集函数中用到了(访问.修改.返回),那么这个变量就被保护起来了 只有自己可以修改,父级函数()()就是闭包函数 2.闭包的特点: 1.常驻内存 ...
- Lucene 写入一个文档到该文档可搜索延迟是多少?
我看的是最初版的lucene,1.4.3 结论是新写入的文档会先写入内存中,只有当到达一定阈值后才会刷新进磁盘,而搜索可以搜索到的数据由最初定义IndexSearcher时磁盘里的段数据决定,如果想要 ...
- js javascript 如何获取某个值在数组中的下标
js 某个值在数组中的下标javascript中知道一个数组中的一个元素的值,如何获取数组下标JS 获取数组某个元素下标 函数方法 采用prototype原型实现方式,查找元素在数组中的索引值js查找 ...
- odoo12 权限配置1
权限配置文档说明,这里使用公司开发的两个权限配置模块,可以快速的帮助你来配置复杂的odoo权限. 安装以下两个模块,SystemGroups模块是快速帮助你批量添加,创建基础群组需要用到的模块 Bas ...
- 关于使用Hadoop MR的Eclipse插件开发时遇到Permission denied问题的解决办法【转】
搭建了一个Hadoop的环境,Hadoop集群环境部署在几个Linux服务器上,现在想使用windows上的Java客户端来操作集群中的HDFS文件,但是在客户端运行时出现了如下的认证错误,被折磨了几 ...
- Django 使用 cookie 实现简单的用户管理
Cookie: 1.保存在用户浏览器 2.可以主动清除 3.可以被伪造 4.跨域名 Cookie 不共享 创建一个项目:user_manager 和应用: app01 创建数据库,添加 models. ...
- css 最后的终章
相对定位:参考点 相对原来的位置 1.如果是一个单独的文档流盒子,及你姐设置了相对定位,和普通盒子一样 2.相对定位后,如果调整位置,会留下坑 作用:微调元素 子绝父相 提升层级 绝对定位 参考点:父 ...
- Spring Boot Quartz 动态配置,持久化
Quartz 是一个很强大的任务调度框架在SpringBoot中也很容易集成 添加依赖: <dependency> <groupId>org.springframework&l ...
- 201871010102-常龙龙《面向对象程序设计(java)》第八周学习总结
项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://www.cnblogs.com/nwnu-daizh/p ...