国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

jQuery實現公告文字左右滾動的實例代碼

2024-05-06 15:53:44
字體:
來源:轉載
供稿:網友
這篇文章介紹了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公告文字左右滾動效果-</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></div>
<script type="text/javascript">
if(document.getElementById('GoogleAD')!=null){
    document.getElementById('GoogleAD').innerHTML = '<div>' + document.getElementById('GoogleADCode').innerHTML + '</div>';
}
</script>
</body>
</html>

       

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 新昌县| 丹寨县| 麦盖提县| 台北县| 隆安县| 清涧县| 信宜市| 九江市| 平定县| 原平市| 八宿县| 嵊泗县| 米林县| 宕昌县| 巧家县| 蚌埠市| 德钦县| 绥芬河市| 咸阳市| 敦煌市| 五峰| 襄汾县| 鄱阳县| 荆门市| 樟树市| 芜湖市| 三河市| 西城区| 崇信县| 梅州市| 庐江县| 大同市| 襄垣县| 团风县| 福海县| 葫芦岛市| 澄迈县| 德江县| 岐山县| 社旗县| 洞口县|