Jquery控制文字横向移动
来源:互联网 发布:蝴蝶效应 知乎 编辑:程序博客网 时间:2024/06/05 04:30
首先html页面代码定义
<div class="navbar-inner" id="s" style="width:600px; position:relative; white-space:nowrap; overflow:hidden; height:60px;">
<div id="noticeList" style="position:absolute; top:0; height:20px;"> <span>截止目前:共提交问卷${alltotal}份,盐田${mt3total}份,蛇口${mt4total}份,赤湾${mt1total}份,大铲${mt2total}份。实时更新中~ </span><div>
</div>
Js代码
方法一:
$.fn.textScroll=
function
(){
var
speed=60,flag=
null
,tt,that=$(
this
),child=that.children();
var
p_w=that.width(), w=child.width();
child.css({left:p_w});
var
t=(w+p_w)/speed * 1000;
function
play(m){
var
tm= m==undefined ? t : m;
child.animate({left:-w},tm,
"linear"
,
function
(){
$(
this
).css(
"left"
,p_w);
play();
});
}
child.on({
mouseenter:
function
(){
var
l=$(
this
).position().left;
$(
this
).stop();
tt=(-(-w-l)/speed)*1000;
},
mouseleave:
function
(){
play(tt);
tt=undefined;
}
});
play();
}
方法二:
$.fn.textScroll=functioon(){
var
p = $(
this
),
c = p.children(),
speed=3000;
// 值越大,速度越小
var
cw = c.width(),pw=p.width();
var
t = (cw / 100) * speed;
var
f =
null
, t1 = 0;
function
ani(tm) {
counttime();
c.animate({ left: -cw }, tm,
"linear"
,
function
() {
c.css({ left: pw });
clearInterval(f);
t1 = 0;
t=((cw+pw)/100)*speed;
ani(t);
});
}
function
counttime() {
f = setInterval(
function
() {
t1 += 10;
}, 10);
}
p.on({
mouseenter:
function
() {
c.stop(
false
,
false
);
clearInterval(f);
console.log(t1);
},
mouseleave:
function
() {
ani(t - t1);
console.log(t1);
}
});
ani(t);
}
最后调用$("#s").textScroll();
使用案例:
<script type="text/javascript">
$.fn.textScroll=function(){
var speed=60,flag=null,tt,that=$(this),child=that.children();
var p_w=that.width(), w=child.width();
child.css({left:p_w});
var t=(w+p_w)/speed * 1000;
function play(m){
var tm= m==undefined ? t : m;
child.animate({left:-w},tm,"linear",function(){
$(this).css("left",p_w);
play();
});
}
child.on({
mouseenter:function(){
var l=$(this).position().left;
$(this).stop();
tt=(-(-w-l)/speed)*1000;
},
mouseleave:function(){
play(tt);
tt=undefined;
}
});
play();
}
$(document).ready(
function(){
$("#s").textScroll();
}
);
</script>
- Jquery控制文字横向移动
- jquery实现图片横向移动
- js 控制div 横向 纵向 移动
- Javascript控制文字移动、图片
- jquery 控制 div 显示文字
- jquery横向平滑移动轮播切换效果
- jquery 控制文字域展开收起
- jquery控制textarea随文字自动增高
- 文字横向滚动效果
- xshell中的横向文字
- 手写横向文字滚动
- 文字横向滚动效果
- jquery 控制table tr 上下移动
- jQuery:用方向键控制层的移动
- jQuery:用方向键控制层的移动
- Jquery 控制元素 上 下 移动
- Jquery 控制元素 上 下 移动
- 横向移动ListView
- 友善之臂第一个裸板驱动LED程序的详细分析(新手向)
- 【学习笔记】系列二:Linux安装配置apache
- document.addEventListener理解
- Android 关闭多个Activity
- 函数执行过程的博大精深,表示不懂啊
- Jquery控制文字横向移动
- orcacle 解决违反约束问题
- Ecmall MySql 数据库调用教程
- 第四周项目三(3)
- iOS8 用UITableViewRowAction实现Cell自定义滑动操作
- The entity name must immediately follow the '&' in the entity reference
- Sql Server参数化查询之where in和like实现详解
- hihocoder 1228 Mission Impossible 6 一道写的我蛋碎的模拟题
- 神奇的TextView