runxinzhi.com
首页
百度搜索
数字倒数效果
当页面初步加载时,显示数字滚动。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/> <title>test</title> <style type="text/css"> *{ margin:0; padding:0;} body{font:12px/1 arial; background:#3f3f3f;} .num{ 500px; padding:10px 0;border-radius:15px;text-shadow:1px 1px 1px #999; color:#fff;text-align:center; margin:120px auto; font-size:62px; font-weight:bold; border:5px solid #ccc; background:#fff;} .num strong{ font-weight:normal; border:1px solid #ccc; background:#333; padding:0 10px; text-align:center;} </style> </head> <body> <div id="num" class="num" style="display:none;">1000000</div> <script type="text/javascript"> String.prototype.repeat = function(n){ return Array(n + 1).join(this); }; var addFixed = 5, // 单次增加值 node = document.getElementById('num'), emTotal = node && node.innerHTML; function numAnim(){ var len = 1, last = 0, // 最终值 n = 0; // 需要填充的空白0 if(addFixed < emTotal){ // 跳出setTimeout条件 addFixed += Math.ceil((emTotal - addFixed) / 3); len = emTotal.length - (addFixed + '').length; last = n + '' + addFixed; n = '0'.repeat(10).slice(len); if(len == 0){ // 如果等于0后删除首位 last = last.slice(1); } last = last.split(''); last = '<strong>' + last.join('</strong><strong>') + '</strong>'; node.innerHTML = last; } setTimeout(numAnim, 100); } node.style.display = 'block'; numAnim(); </script> </body> </html>
运行代码
相关阅读:
经典基础算法之面试题(系列一)
Shell脚本中的二维字符串列表
网络字节流数据解析组件的设计与实现Circular Buffer(Ring Buffer)
Django开发环境搭建(Windows+Python2.6)
C++中堆(优先队列)的应用:make_heap, pop_heap, push_heap, sort_heap, priority_queue
求逆序数的快速算法归并排序
经典基础算法之BST详解(系列二)
PHP数组去重
微信小程序分享设置
微信小程序判断开发环境
原文地址:https://www.cnblogs.com/jikey/p/2736599.html
最新文章
红外遥控发射和接收关系
HDOJ 3397 Sequence operation
USACO sec2.1 Healthy Holsteins
HDOJ 4027 Can you answer these queries?
2012 MultiUniversity Training Contest 4 D Trouble
[hash] PKU 2002 Squares
USACO sec1.5 Superprime Rib
PKU 3667 Hotel
[最小表示]PKU 3349 Snowflake Snow Snowflakes
USACO sec2.1 Ordered Fractions
热门文章
[转载]PKU 水题集
[2012.10.13] 省赛总结
USACO sec2.1 Hamming Codes
USACO sec1.5 Prime Palindromes
PKU 3225 Help with Intervals
USACO sec1.5 Checker Challenge
堆排序
[数组hash] PKU 3274 Gold Balanced Lineup
PKU 2892 Tunnel Warfare
[二分] PKU 1840 Eqs
Copyright © 2020-2023
润新知