JQuery implementation of the announcement text scroll left and right instance code
- 2020-03-26 21:41:52
- OfStack
<!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 Notice text scroll effect left and right -www.jb51.net</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);
}
}
}
}
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- about scrolling effect -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
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}//Space between moves exceeds limit (unit :px)
if(Interval<1){Interval = 10}//Time interval per movement (in milliseconds)
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,' Welcome to script house! ','left',1,20);//Scrolling marquee
});
</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>