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 ...
随机推荐
- C# 读取与修改配置文件
System.Configuration.ConfigurationSettings.AppSettings["Key"]; 但是现在FrameWork2.0已经明确表示此属性已经 ...
- raspberry pi vpn
http://raspberrypihelp.net/tutorials/1-openvpn-server-tutorialhttp://www.jacobsalmela.com/setting-up ...
- Android小项目之六 apk下载
------- 源自梦想.永远是你IT事业的好友.只是勇敢地说出我学到! ---------- 按惯例,写在前面的:可能在学习Android的过程中,大家会和我一样,学习过大量的基础知识,很多的知识点 ...
- oracle数据库例外处理与视图
pl/sql例外处理 例 当输入编号没有时的例外处理 declare --定义 v_ename emp.ename%type; begin -- select ename into v_ename f ...
- zend studio常见问题解答
1.如何实现zend studio成为注册版请点击查看此链接http://www.geekso.com/ZendStudio100/ 2.如何将zend studio的默认GBK编码设置为其它编码,例 ...
- LearnMVC5-AddAView
原创文章,转载必需注明出:http://www.ncloud.hk/%E6%8A%80%E6%9C%AF%E5%88%86%E4%BA%AB/learnmvc5-addaview/ 添加视图 在本章节 ...
- 宽度的100%和auto的区别
前段时间做项目,发现分不清width设为100%和auto的区别,实在是太水了,就查了点资料,做个总结,有不对的地方欢迎大家指出. width:auto 块级元素默认的宽度值.看一下MDN上的解释:T ...
- 公用的stringUtil工具
(function(){ var ISCHINESE = /[\u4e00-\u9fa5]/; var getData = function( value , maxLenth , isStrick ...
- 【转】自己动手写SC语言编译器
自序 编译原理与技术的一整套理论在整个计算机科学领域占有相当重要的地位,学习它对程序设计人员有很大的帮助.我们考究历史会发现那些人人称颂的程序设 计大师都是编译领域的高手,像写出BASIC语言的BIL ...
- git and github学习笔记
1.git的状态分为working status,stage status和commit status.git diff查看的是working status和 stage status之间的不同,gi ...