jQuery实现公告文字左右滚动
jQuery实现公告文字左右滚动的代码。
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>jQuery公告文字左右滚动效果-www.jbxue.com</title>
<style type="text/css">
#scrollText {
width: 400px;
margin-right: auto;
margin-left: auto;
}
</style>
</head>
<script type="text/javascript" src="/source/js/jquery-1.6.2.min.js"></script>
<script type="text/javascript">
var ScrollTime;
function ScrollAutoPlay(contID,scrolldir,showwidth,textwidth,steper){
var PosInit,currPos;
with($('#'+contID)){
currPos = parseInt(css('margin-left'));
if(scrolldir=='left'){
if(currPos<0 && Math.abs(currPos)>textwidth){
css('margin-left',showwidth);
}
else{
css('margin-left',currPos-steper);
}
}
else{
if(currPos>showwidth){
css('margin-left',(0-textwidth));
}
else{
css('margin-left',currPos-steper);
}
}
}
} //--------------------------------------------左右滚动效果----------------------------------------------
/*
AppendToObj: 显示位置(目标对象)
ShowHeight: 显示高度
ShowWidth: 显示宽度
ShowText: 显示信息
ScrollDirection: 滚动方向(值:left、right)
Steper: 每次移动的间距(单位:px;数值越小,滚动越流畅,建议设置为1px)
Interval: 每次执行运动的时间间隔(单位:毫秒;数值越小,运动越快)
*/
function ScrollText(AppendToObj,ShowHeight,ShowWidth,ShowText,ScrollDirection,Steper,Interval){
var TextWidth,PosInit,PosSteper;
with(AppendToObj){
html('');
css('overflow','hidden');
css('height',ShowHeight+'px');
css('line-height',ShowHeight+'px');
css('width',ShowWidth);
}
if (ScrollDirection=='left'){
PosInit = ShowWidth;
PosSteper = Steper;
}
else{
PosSteper = 0 - Steper;
}
if(Steper<1 || Steper>ShowWidth){Steper = 1}//每次移动间距超出限制(单位:px)
if(Interval<1){Interval = 10}//每次移动的时间间隔(单位:毫秒)
var Container = $('<div></div>');
var ContainerID = 'ContainerTemp';
var i = 0;
while($('#'+ContainerID).length>0){
ContainerID = ContainerID + '_' + i;
i++;
}
with(Container){
attr('id',ContainerID);
css('float','left');
css('cursor','default');
appendTo(AppendToObj);
html(ShowText);
TextWidth = width();
if(isNaN(PosInit)){PosInit = 0 - TextWidth;}
css('margin-left',PosInit);
mouseover(function(){
clearInterval(ScrollTime);
});
mouseout(function(){
ScrollTime = setInterval("ScrollAutoPlay('"+ContainerID+"','"+ScrollDirection+"',"+ShowWidth+','+TextWidth+","+PosSteper+")",Interval);
});
}
ScrollTime = setInterval("ScrollAutoPlay('"+ContainerID+"','"+ScrollDirection+"',"+ShowWidth+','+TextWidth+","+PosSteper+")",Interval);
}
</script>
<script type="text/javascript">
$(document).ready(function(e) {
ScrollText($('#scrollText'),23,400,'欢迎光临脚本学习网!','left',1,20);//滚动字幕
});
</script>
<body>
<div id="scrollText"></div>
<script type="text/javascript">
if(document.getElementById('GoogleAD')!=null){
document.getElementById('GoogleAD').innerHTML = '<div class="SearchEngine_AD1">' + document.getElementById('GoogleADCode').innerHTML + '</div>';
}
</script>
</body>
</html>
jQuery实现公告文字左右滚动的更多相关文章
- jQuery实现公告文字左右滚动的代码。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Expression Blend4经验分享:文字公告无缝循环滚动效果
这次分享一个类似新闻公告板的无缝循环滚动效果,相信很多项目都会应用到这个效果.之前我也百度了一下,网上的一些Silverlight的文字或图片滚动效果,都是一次性滚动的,如果要做到无缝循环滚动,多数要 ...
- jquery文字上下滚动的实现方法
jquery实现文字上下滚动的方法. 代码: //上下滚动var textRoll=function(){$('#notice p:last').css({'height':'0px','opacit ...
- jquery文字左右滚动
实现jquery文字左右滚动 <div class="fl">中奖名单:</div> <div class="scrollText" ...
- jquery 文字向上滚动+CSS伪类before和after的应用
汇总常用技巧——CSS伪类before和after的应用 先上效果图,建议遵循有图有真相的原则,可以上图的地方,还望不要嫌麻烦,毕竟有图的话 可以让读者少花些时间! <!DOCTYPE html ...
- jquery垂直公告滚动实现代码
公告滚动想必大家都有见到过吧,实现方法也有很多,下面为大家介绍使用jquery实现垂直公告滚动,感兴趣的朋友不要错过 复制代码代码如下: <!DOCTYPE html PUBLIC " ...
- jquery实现文字上下滚动效果
文字上下滚动是经常用到的js效果,这里介绍一种上下渐隐渐出的文字展现效果! 代码实现很简单,只需要引入jquery就可以. 代码如下: <!DOCTYPE> <head> &l ...
- jQuery实现文字横向滚动效果
HTML代码: <div id="aaa" style="width:100px; position:relative; white-space:nowrap; o ...
- Taro -- 文字左右滚动公告效果
文字左右滚动公告效果 设置公告的左移距离,不断减小,当左移距离大于公告长度(即公告已移出屏幕),重新循环. <View className='scroll-wrap'> <View ...
随机推荐
- Socket 之 原理与编程基础
一.Socket简介 Socket是进程通讯的一种方式,即调用这个网络库的一些API函数实现分布在不同主机的相关进程之间的数据交换. 几个定义: (1)IP地址:即依照TCP/IP协议分配给本地主机的 ...
- C# unix时间戳转换
场景:由于业务需要和java 开发的xxx系统对接日志,xxx系统中用“1465195479100” 来表示时间,C# 里面需要转换做一下逻辑处理,见代码段. C#获取的unix时间戳是10位,原因是 ...
- IOS 读取本地的Json/plist 文件
一.一般本地可以存储轻量级数据存储 plist 这个主要是操作字典 方法如下: NSString * sampleFile= [[[NSBundle mainBundle] bundlePath] ...
- 通过layer的contents属性来实现uiimageview的淡入切换
#import "ViewController.h" @interface ViewController () @property(nonatomic,strong)CALayer ...
- 【¥200代金券、iPad等您来拿】 阿里云9大产品免费公测#10月9日-11月6日#
#10.09-11.06#200元代金券.iPad大奖, 9大产品评测活动! 亲爱的阿里云小伙伴们: 云产品的多样性(更多的云产品)也是让用户深度使用云计算的关键.今年阿里云产品线越来越丰富,小云搜罗 ...
- nodejs 安装 postgresql module
# npm -gd install node-gyp # export PATH=$PATH:/usr/local/pgsql/bin # npm -gd install pg for test: # ...
- Precompile Prefix file(.pch文件)
参考资料: http://blog.csdn.net/lwjok2007/article/details/46385595 http://www.tuicool.com/articles/beURbe ...
- Delphi单元文件之-防止程序重复执行
//工程引用此单元就能防止同时出现多个实例unit MultInst;interfaceuses Windows ,Messages, SysUtils, Classes, Forms;impleme ...
- hdu1880
魔咒词典 Time Limit: 8000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- 【.NET基础】--委托、事件、线程(3)
之前的两篇文章我们了解了委托和事件,本文我们看一下线程. 1,一个窗体程序,默认拥有一个线程(相当于一个商店里面,只有一个店员),这个默认的线程叫做 UI线程/主线程. 2,进程和线程的关系: A,进 ...