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 ...
随机推荐
- SQL Server备份时间段内插入的数据依旧进入了备份文件?(转载)
问 MSSql我在本机测试了下.为了延长备份时间,找个大的数据库.开始完整备份bak然后再此库新建表,并增添数据.备份结束.==================还原备份后,在还原的数据库内发现新增的表 ...
- .NET Core跨平台部署于Docker(Centos)- 视频教程
(双击全屏播放) 往期教程: .NET开发框架(一)-框架介绍与视频演示 .NET开发框架(二)-框架功能简述 .NET开发框架(三)-高可用服务器端设计 .NET开发框架(四)-服务器IIS实践教程 ...
- OWIN详细介绍
1.OWIN.dll介绍 用反编译工具打开Owin.dll,你会发现类库中就只有一个IAppBuilder接口,所以说OWIN是针对.NET平台的开放Web接口. public interface I ...
- Docker(Linux)学习笔记以及Redis/MariaDB的容器使用后台全自动启动
1:Docker安装,由于Docker后续pull镜像的服务器默认是在国外的,速度实在是太慢,这里使用阿里云的镜像 阿里云的Docker CE 镜像源站进行安装 docker ===========U ...
- Java编程基础——数组和二维数组
Java编程基础——数组和二维数组 摘要:本文主要对数组和二维数组进行简要介绍. 数组 定义 数组可以理解成保存一组数的容器,而变量可以理解为保存一个数的容器. 数组是一种引用类型,用于保存一组相同类 ...
- Java开发中对Redis的基本操作
Jedis操作redis指令 import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; impo ...
- HttpHelper之我见
前几月一直用一个Http的访问类去调用WebApi,说句实话最开始没觉有什么,一是技术老,二是觉得比较简单,但是最近我一直关注云开发和AI这块儿微软技术,看到云平台调用API大多类似,所以回想这个早年 ...
- Mobx总结以及mobx和redux区别
Mobx解决的问题 传统react使用的数据管理库为Redux.Redux要解决的问题是统一数据流,数据流完全可控并可追踪.要实现该目标,便需要进行相关的约束 Redux由此引出dispatch ac ...
- vue中输入框只能输入数字
方案1:增加自定义指令 自定义指令写法: directives: { numberOnly: { bind(el) { ...
- E203译码模块(3)
下面的代码译码出指令的立即数,不同的指令有不同的立即数编码形式. //I类型指令的imm,[31:20],符号位扩展成32位. wire [31:0] rv32_i_imm = { {20{rv32_ ...