js 文字左滚动

JavaScript015

js 文字左滚动,第1张

这是JS

<script type="text/javascript">

               

                   $(function(){

                    var speed = 30

                    var topscroll = document.getElementById("divkuaixunxinxi")

                    var scrolla = document.getElementById("topscrolla")

                    var scrollb = document.getElementById("topscrollb")

                    var scroll  = document.getElementById("scroll")

                    var isIE6_7 = false

                    if($.browser.msie&&($.browser.version == "6.0")&&!$.support.style || $.browser.msie&&($.browser.version == "7.0")){

                        scroll.style.width="1600px"

                        isIE6_7 = true

                    }else{

                        scroll.style.width=(scrolla.offsetWidth*2-50)+"px"

                    }

                    

                        scrollb.innerHTML = scrolla.innerHTML

                        function Marquee() {

                            if (scrollb.offsetWidth -  topscroll.scrollLeft <=0)

                                topscroll.scrollLeft -= scrolla.offsetWidth

                            else {

                                topscroll.scrollLeft++

                                if(isIE6_7 && topscroll.scrollLeft > 1718){

                                topscroll.scrollLeft -= scrolla.offsetWidth

                                }

                            }

                        }

                        var mar = setInterval(Marquee, speed)

                        topscroll.onmouseover = function() { clearInterval(mar) }

                        topscroll.onmouseout = function() { mar = setInterval(Marquee, speed) }

                  })

        </script>

        这是HTML

        <div id="divkuaixunxinxi" class="kuaixunxinxi">

                <div id="scroll">

                    <div id="topscrolla">

                                   ·<a>平价私享天堂假期3日梦幻爱昵岛</a>平价私享天堂假期3日梦幻爱昵岛&nbsp&nbsp·平价私享天堂假期3日梦幻爱昵岛&nbsp&nbsp·平价私享天堂假期3日梦幻爱昵岛&nbsp&nbsp·平价私享天堂假期3日梦幻爱昵岛 

                    </div>

                    <div id="topscrollb">

                    </div>

                </div>

            </div>

可以实现匀速、无缝、加链接以及其它的修饰效果,本代码就是实现了这一功能,让文字从右至右平滑滚动,滚动宽度、高度、速度均可以设定。

Js文字向左运动

var

marqueewidth=350

var

marqueeheight=22

var

speed=5

var

marqueecontents='欢迎光临脚本之家

网页特效栏目,精品特效全收罗!'

if

(document.all)

document.write(''+marqueecontents+'')

function

regenerate(){

window.location.reload()

}

function

regenerate2(){

if

(document.layers){

setTimeout("window.onresize=regenerate",450)

intializemarquee()

}

}

function

intializemarquee(){

document.cmarquee01.document.cmarquee02.document.write(''+marqueecontents+'')

document.cmarquee01.document.cmarquee02.document.close()

thelength=document.cmarquee01.document.cmarquee02.document.width

scrollit()

}

function

scrollit(){

if

(document.cmarquee01.document.cmarquee02.left>=thelength*(-1)){

document.cmarquee01.document.cmarquee02.left-=speed

setTimeout("scrollit()",100)

}

else{

document.cmarquee01.document.cmarquee02.left=marqueewidth

scrollit()

}

}

window.onload=regenerate2

[Ctrl+A

全选

注:如需引入外部Js需刷新才能执行]