文字横向滚动效果
来源:互联网 发布:仓储物流软件系统 编辑:程序博客网 时间:2024/05/21 11:20
1.利用jQuery的animta方法
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>TEXT-MOVE</title> <script SRC="../lib/jquery.min.js"></script> <style type="text/css" rel="stylesheet"> * { margin: 0; padding: 0; } .container { margin: 200px auto; width: 500px; height: 50px; line-height: 50px; border: 1px solid red; overflow: hidden; } .text { display: inline-block; white-space: nowrap; } </style></head><body><div class="container"> <p class="text">我是一段滚动的文字我是一段滚动的文字我是一段滚动的文字我是一段滚动的文字我是一段滚动的文字</p></div><script> var $container = $('.container'), $text = $('.text'); var direction = 1, // 1为从左进入,2为从右进入 speed = 3000; // 数值越小速度越快 var textMove = function (obj, container, direction, speed) { // 定义文字初始位置 var initMarginLeft = '-' + obj.width() + 'px'; obj.css({"margin-left": initMarginLeft}); // 定义动画 var move = function () { // 定义暂停后的速度 var allDistance = obj.width() + container.width(), remainedDistance = container.width() - parseInt(obj.css('margin-left')), currentSpeed = (speed * remainedDistance ) / allDistance; // 移动效果 obj.animate({"margin-left": container.width() + 'px'}, currentSpeed, 'linear', function () { obj.stop(true, true); obj.css({"margin-left": initMarginLeft}); move(); }); }; move(); // 定义容器的暂停、恢复效果 container.on("mouseenter", function () {obj.stop(true)}) .on('mouseleave', function () {move()}) }; textMove($text, $container, direction, speed);</script></body></html>
2. 利用CSS3的keyframe规则
- 目前浏览器都不支持 @keyframes 规则。
- Firefox 支持替代的 @-moz-keyframes 规则。
- Opera 支持替代的 @-o-keyframes 规则。
- Safari 和 Chrome 支持替代的 @-webkit-keyframes 规则。
通过 @keyframes 规则,您能够创建动画。
创建动画的原理是,将一套 CSS 样式逐渐变化为另一套样式。
在动画过程中,您能够多次改变这套 CSS 样式。
以百分比来规定改变发生的时间,或者通过关键词 “from” 和 “to”,等价于 0% 和 100%。
0% 是动画的开始时间,100% 动画的结束时间。
为了获得最佳的浏览器支持,您应该始终定义 0% 和 100% 选择器。
注释:请使用动画属性来控制动画的外观,同时将动画(天然与选择器绑定)。
语法:
@keyframes animationname {keyframes-selector {css-styles;}}
- nimationname–必需。定义动画的名称。
- keyframes-selector–必需。动画时长的百分比。合法的值:0-100%from(与 0% 相同)to(与 100% 相同)
- css-styles 必需。一个或多个合法的 CSS 样式属性。
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>TEXT-MOVE</title> <script SRC="../lib/jquery.min.js"></script> <style type="text/css" rel="stylesheet"> * { margin: 0; padding: 0; } .container { margin: 200px auto; width: 500px; height: 50px; line-height: 50px; border: 1px solid red; overflow: hidden; } .text { position: relative; display: inline-block; white-space: nowrap; /*animation:scroll 5s 0s linear infinite;*/ animation-name: scroll; animation-duration: 5s; animation-delay: 0ms; animation-timing-function: linear; animation-iteration-count: infinite; -webkit-animation-name: scroll; -webkit-animation-delay: 0ms; -webkit-animation-duration: 5s; -webkit-animation-timing-function: linear; -webkit-animation-iteration-count: infinite; -moz-animation-name: scroll; -moz-animation-delay: 0ms; -moz-animation-duration: 5s; -moz-animation-timing-function: linear; -moz-animation-iteration-count: infinite; } @-webkit-keyframes scroll { 100% { margin-left: 100%; } } @-moz-keyframes scroll { 100% { margin-left: 100%; } } @-ms-keyframes scroll { 100% { margin-left: 100%; } } .text:hover { -webkit-animation-play-state: paused; } </style></head><body><div class="container"> <p class="text">我是一段滚动的文字我是一段滚动的文字我是一段滚动的文字我是一段滚动的文字我是一段滚动的文字</p></div><script> var $text = $('.text'); var initMarginLeft = '-' + $text.width() + 'px'; $text.css({"margin-left": initMarginLeft});</script></body></html>
阅读全文
0 0
- 文字横向滚动效果
- 文字横向滚动效果
- 横向不间断的文字滚动效果
- TextView文字横向滚动(跑马灯效果)
- 手写横向文字滚动
- 文字横向滚动的实现
- 文字横向滚动的实现
- JS中文字横向滚动
- TextView文字横向自动滚动
- js实现文字横向滚动
- 文字横向滚动的TextView
- JS横向无缝滚动效果
- android 图片横向滚动效果
- android 图片横向滚动效果
- android 图片横向滚动效果
- RecyclerView 实现横向滚动效果
- RecyclerView 实现横向滚动效果
- adnroid textview设置文字横向自动滚动(跑马灯效果)
- Hypermesh 12.0 中球体的六面体网格划分
- 支付宝小程序手机端获取数据失败,电脑模拟器正常
- Java
- Java进阶之路——从初级程序员到架构师,从小工到专家
- Android studio 安装遇到的问题
- 文字横向滚动效果
- 3. 括号匹配
- 阿里云ECS部署tomcat web的过程
- 计算机视觉学习及Google的autom的NasNet
- 红黑树简要总结
- 11.03 CSS的基本使用
- java 包装类之Integer -Character
- Mysql、Oracle、Hive中查找表、数据库
- Android 根据color id 获取颜色16进制值