随鼠标飘浮移动文字的javascript 源代码

JavaScript037

随鼠标飘浮移动文字的javascript 源代码,第1张

<html>

<head><script>

var x,y

var step=40

var flag=0

var message="欢迎我的网站"

message=message.split("")

var xpos=new Array()

for (i=0i<=message.lengthi++) {

xpos[i]=-50}

var ypos=new Array()

for (i=0i<=message.lengthi++) {

ypos[i]=-50}

function handlerMM(e){

x = (document.layers) ? e.pageX : document.body.scrollLeft+event.clientX

y = (document.layers) ? e.pageY : document.body.scrollTop+event.clientY

flag=1}

function makeit() {

if (flag==1 &&document.all) {

for (i=message.lengthi>=1i--) {

xpos[i]=xpos[i-1]+step

ypos[i]=ypos[i-1] }

xpos[0]=x+step

ypos[0]=y

for (i=0i<message.lengthi++) {

var thisspan = eval("span"+(i)+".style")

thisspan.posLeft=xpos[i]

thisspan.posTop=ypos[i] } }

else if (flag==1 &&document.layers) {

for (i=message.lengthi>=1i--) {

xpos[i]=xpos[i-1]+step

ypos[i]=ypos[i-1] }

xpos[0]=x+step

ypos[0]=y

for (i=0i<message.lengthi++) {

var thisspan = eval("document.span"+i)

thisspan.left=xpos[i]

thisspan.top=ypos[i]} }

var timer=setTimeout("makeit()",30)}

for (i=0i<=message.lengthi++) {

document.write("<span id='span"+i+"'class='spanstyle'>")

document.write(message[i])

document.write("</span>")}

if (document.layers){

document.captureEvents(Event.MOUSEMOVE)}

document.onmousemove = handlerMM

</script>

<title>跟随鼠标的飘带文字</title>

<style type="text/css">

.spanstyle {position:absolutevisibility:visibletop:-50pxfont-size:9ptcolor: #c800c0font-weight:bold}</style>

</head>

<body onLoad="makeit()">

</body>

</html>

把两段JS脚本合为一个:

<script language="JavaScript" type="text/javascript">

if (navigator.appName.indexOf('Netscape') == '-1')

{

var colors = ["#000000","#FF5500","#000000","#FF5500","#000000","#FF5500"]

var nextcolor = 0

var nextcolor1 = 1

function changecolor()

{

document.all.FlashText1.style.color = colors[nextcolor++]

document.all.FlashText2.style.color = colors[nextcolor1++]

nextcolor = nextcolor % colors.length

nextcolor1 = nextcolor1 % colors.length

}

setInterval("changecolor()", 200)

}

</script>

用document.getElementById(div1)获取到该div,然后操作它就行了,如果是文本上下移动完全可以使用marquee标签。

引用JS:

www.cyin.cn/js/front/supermarquee.js

HTML代码:

<div class="zuixinxuqiu" style="height: 197pxwidth: 678pxoverflow: hiddenposition: relative">

<ul>

<dl class="clearfix">

<dt class="coladdress">

成都市</dt>

</dl>

<dl class="clearfix">

<dt class="coladdress">

成都市</dt>

</dl>

<dl class="clearfix">

<dt class="coladdress">

成都市</dt>

</dl>

<dl class="clearfix">

<dt class="coladdress">

成都市</dt>

</dl>

<dl class="clearfix">

<dt class="coladdress">

成都市</dt>

</dl>

</ul>

</div>

执行JS:

$(".zuixinxuqiu").kxbdSuperMarquee({

isEqual: false,

distance: 33,

time: 5,

direction: 'up'

})