css 层滚动问题

html-css07

css 层滚动问题,第1张

这种效果直接实现基本上已经是不能得了(个人是想不出了哈~~)

不过可以绕个弯来实现这个效果。

先确定一下你要的效果(以免回答的牛头不对马嘴):

左边的导航始终固定不动,在左上角,右边的内容虽浏览器的滚动条拖动自动向下滚动以可以查看所有内容。

(如果确定的话,就可以接着往下看,不对的话,你就再补充下哈)

大致实现代码如下:

<html>

<head>

<style type="text/css">

div#left

{

float:left

position:absolute

top:expression(document.body.scrollTop+this.offsetHeight)

//关键是这两句!!!使左边的导航层始终相对浏览器左上角某个位置固定。

left:5px

width:25%

border:solid 2px red

}

div#right

{

float:right

width:70%

border:solid 2px red

height:1000px//这里测试滚动使用。

}

</style>

</head>

<body>

<div id="left">相对于浏览器(而非网页文档)左上角绝对定位。</div>

<div id="right">主内容</div>

</body>

</html>

OK~~,你可以直接复制粘贴测试了,看一下效果对不对(去掉注释哈)

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的

有三种代码输入的方式可以在CSS隐藏滚动条。

详细方法如下:

方法一:

代码如下:

html { overflow-y: scroll}

原理:强制显示ie的垂直滚动条,而忽略水平滚动条;

优点:完全解决了这个问题, 允许你保持完整的XHTML doctype.;

缺点:即使页面不需要垂直滚动条的时候也会出现垂直滚动条;

方法二:(推荐采用)

代码如下:

html { overflow-x: hiddenoverflow-y: auto}

原理:隐藏横向滚动,垂直滚动根据内容自适应;

优点:在视觉上解决了这个问题.在不必要的时候, 未强制垂直滚动条出现;

缺点:只是隐藏了水平滚动条,如果页面真正需要水平滚动条的时候,屏幕以外的内容会因为用户无法水平滚动,而看不到;

方法三:

代码如下:

body { margin-right: -15pxmargin-bottom: -15px}

原理:这会在margin的水平和垂直方向上添加一个负值, IE添加了该精确数值后, 便会去除对滚动条的需求假象;

优点:在视觉上解决了这个问题,垂直滚动根据内容自适应;

缺点:由于"人为创建"了15px的外边距(margin), 所以无法使用该填充过的屏幕区域。