CSS怎样使文字向上滚动时从顶端开始滚动而不是从底部。

html-css09

CSS怎样使文字向上滚动时从顶端开始滚动而不是从底部。,第1张

网上代码很多的,不过基本上用层,用marquee好像不行(表示没有深究过),我粘贴了一段,你看看吧,希望对你有帮助。

<!DOCTYPE html>

<HTML> 

<HEAD> 

<TITLE> New Document </TITLE> 

<script> 

var a=12 

function moveup(){ 

if (a>-1000){ 

eval("qq.style.top='"+a+"'") 

a-- 

up=setTimeout('moveup()',1) 

function movedown(){ 

if (a<13){ 

eval("qq.style.top='"+a+"'") 

a++ 

down=setTimeout('movedown()',1) 

</script> 

</HEAD> 

<BODY> 

<div style="position:absolutetop:12clip:rect(0 130pt 130pt 0)height:130ptwidth:130ptborder:solid 1 black"> 

<div id=qq style="position:absolutepadding:5pttop:12height:130ptwidth:130ptfont:9pt/2.5 新宋体"> &nbsp&nbsp曾子仕于莒,

得粟三秉,方是之时,曾子重其禄而轻其身;亲没之后,齐迎以相,楚迎以令尹,晋迎以上卿,方是之时,曾子重其身而轻其禄。怀其宝而迷其国者,

不可与语仁;窘其身而约其亲者,不可与语孝;任重道远者,不择地而息;家贫亲老者,不择官而仕。故君子桥褐趋时,当务为急。传云:不逢时而仕

,任事而敦其虑,为之使而不入其谋,贫焉故也。诗云:“夙夜在公,实命不同。” &nbsp&nbsp传曰:夫行露之人许嫁矣,然而未往也,见一物不

具,一礼不备,守节贞理,守死不往,君子以为得妇道之宜,故举而传之,扬而歌之,以绝无道之求,防污道之行乎!诗曰:“虽速我讼,亦不尔从。

”…… 

</div></div> 

<div style="position:absolutetop:160ptleft:80ptfont:11pt"><span onMouseOver="moveup()" onMouseOut="clearTimeout

(up)">Up</span>&nbsp&nbsp<span onMouseOver="movedown()" onMouseOut="clearTimeout(down)">Down</span></div> 

</BODY> 

</HTML>

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159!DOCTYPEhtmlheadmetahttp-equiv="Content-Type"content="text/htmlcharset=gb2312"/title向上下左右不间断无缝滚动效果(兼容火狐和IE)/title/headbodydivid="colee"style="overflow:hiddenheight:253pxwidth:410px"divid="colee1"p此处放文字。。。。。。。。。/pp此处放文字。。。。。。。。。/pp此处放文字。。。。。。。。。/pp此处放文字。。。。。。。。。/pp此处放文字。。。。。。。。。/pp此处放文字。。。。。。。。。/pp此处放文字。。。。。。。。。/pp此处放文字。。。。。。。。。/pp此处放文字。。。。。。。。。/pp此处放文字。。。。。。。。。/pp此处放文字。。。。。。。。。/pp此处放文字。。。。。。。。。/p/divdivid="colee2"/div/divscriptvarspeed=30varcolee2=document.getElementById("colee2")varcolee1=document.getElementById("colee1")varcolee=document.getElementById("colee")colee2.innerHTML=colee1.innerHTML//克隆colee1为colee2functionMarquee1(){//当滚动至colee1与colee2交界时if(colee2.offsetTop-colee.scrollTop=0){colee.scrollTop-=colee1.offsetHeight//colee跳到最顶端}else{colee.scrollTop++}}varMyMar1=setInterval(Marquee1,speed)//设置定时器//鼠标移上时清除定时器达到滚动停止的目的colee.onmouseover=function(){clearInterval(MyMar1)}//鼠标移开时重设定时器colee.onmouseout=function(){MyMar1=setInterval(Marquee1,speed)}/script!--向上滚动代码结束--!--下面是向下滚动代码--divid="colee_bottom"style="overflow:hiddenheight:253pxwidth:410px"divid="colee_bottom1"pimgsrc="/jscss/demoimg/200907/bg3.jpg"/ppimgsrc="/jscss/demoimg/200907/bg3.jpg"/ppimgsrc="/jscss/demoimg/200907/bg3.jpg"/ppimgsrc="/jscss/demoimg/200907/bg3.jpg"/ppimgsrc="/jscss/demoimg/200907/bg3.jpg"/ppimgsrc="/jscss/demoimg/200907/bg3.jpg"/ppimgsrc="/jscss/demoimg/200907/bg3.jpg"/ppimgsrc="/jscss/demoimg/200907/bg3.jpg"/ppimgsrc="/jscss/demoimg/200907/bg3.jpg"/p/divdivid="colee_bottom2"/div/divscriptvarspeed=30varcolee_bottom2=document.getElementById("colee_bottom2")varcolee_bottom1=document.getElementById("colee_bottom1")varcolee_bottom=document.getElementById("colee_bottom")colee_bottom2.innerHTML=colee_bottom1.innerHTMLcolee_bottom.scrollTop=colee_bottom.scrollHeightfunctionMarquee2(){if(colee_bottom1.offsetTop-colee_bottom.scrollTop=0)colee_bottom.scrollTop+=colee_bottom2.offsetHeightelse{colee_bottom.scrollTop--}}varMyMar2=setInterval(Marquee2,speed)colee_bottom.onmouseover=function(){clearInterval(MyMar2)}colee_bottom.onmouseout=function(){MyMar2=setInterval(Marquee2,speed)}/script!--向下滚动代码结束--!--下面是向左滚动代码--divid="colee_left"style="overflow:hiddenwidth:500px"tablecellpadding="0"cellspacing="0"border="0"trtdid="colee_left1"valign="top"align="center"tablecellpadding="2"cellspacing="0"border="0"tralign="center"tdpimgsrc="/jscss/demoimg/200907/bg3.jpg"/p/tdtdpimgsrc="/jscss/demoimg/200907/bg3.jpg"/p/tdtdpimgsrc="/jscss/demoimg/200907/bg3.jpg"/p/tdtdpimgsrc="/jscss/demoimg/200907/bg3.jpg"/p/tdtdpimgsrc="/jscss/demoimg/200907/bg3.jpg"/p/tdtdpimgsrc="/jscss/demoimg/200907/bg3.jpg"/p/tdtdpimgsrc="/jscss/demoimg/200907/bg3.jpg"/p/td/tr/table/tdtdid="colee_left2"valign="top"/td/tr/table/divscript//使用div时,请保证colee_left2与colee_left1是在同一行上.varspeed=30//速度数值越大速度越慢varcolee_left2=document.getElementById("colee_left2")varcolee_left1=document.getElementById("colee_left1")varcolee_left=document.getElementById("colee_left")colee_left2.innerHTML=colee_left1.innerHTMLfunctionMarquee3(){if(colee_left2.offsetWidth-colee_left.scrollLeft=0)//offsetWidth是对象的可见宽度colee_left.scrollLeft-=colee_left1.offsetWidth//scrollWidth是对象的实际内容的宽,不包边线宽度else{colee_left.scrollLeft++}}varMyMar3=setInterval(Marquee3,speed)colee_left.onmouseover=function(){clearInterval(MyMar3)}colee_left.onmouseout=function(){MyMar3=setInterval(Marquee3,speed)}/script!--向左滚动代码结束--!--下面是向右滚动代码--divid="colee_right"style="overflow:hiddenwidth:500px"tablecellpadding="0"cellspacing="0"border="0"trtdid="colee_right1"valign="top"align="center"tablecellpadding="2"cellspacing="0"border="0"tralign="center"tdpimgsrc="/jscss/demoimg/200907/bg3.jpg"/p/tdtdpimgsrc="/jscss/demoimg/200907/bg3.jpg"/p/tdtdpimgsrc="/jscss/demoimg/200907/bg3.jpg"/p/tdtdpimgsrc="/jscss/demoimg/200907/bg3.jpg"/p/tdtdpimgsrc="/jscss/demoimg/200907/bg3.jpg"/p/td/tr/table/tdtdid="colee_right2"valign="top"/td/tr/table/divscriptvarspeed=30//速度数值越大速度越慢varcolee_right2=document.getElementById("colee_right2")varcolee_right1=document.getElementById("colee_right1")varcolee_right=document.getElementById("colee_right")colee_right2.innerHTML=colee_right1.innerHTMLfunctionMarquee4(){if(colee_right.scrollLeft=0)colee_right.scrollLeft+=colee_right2.offsetWidthelse{colee_right.scrollLeft--}}varMyMar4=setInterval(Marquee4,speed)colee_right.onmouseover=function(){clearInterval(MyMar4)}colee_right.onmouseout=function(){MyMar4=setInterval(Marquee4,speed)}/script!--向右滚动代码结束--/body/html常用JS图片、文字滚动(...大小:1.41K 已经过百度安全检测,放心下载点击下载

追问

这是JS的代码?我要的HTML的

你的例子中内容的宽度不够,高度有余。虽然overflow:scroll左右,上下滚动条都显示出来了,但是你输入的内容高度不够,所以上下滚动条基本没用。

你多输入几行就能看到上下也可以滚动了。

如果设置overflow:auto。滚动条就可以自动按情况显示或隐藏了。

另外,overflow-x,overflow-y可以单独设置左右或上下滚动。