日期:2014-05-16  浏览次数:20346 次

用图片替换html中的滚动条
现在有个需求是用自己的图片替换默认的IE的滚动条,我对js基本是不懂。
因为现在已经有个模块用的是htm做的。我在网上也找到了相关的代码,这个代码可以实现我需要的大部分功能,但是有一点没做到就是:当htm内的文本是动态变化的时候,在文本很短没有超过htm页面大小时,滚动条不显示,当超过了页面大小时,才显示滚动条。这点我不知道怎么做,麻烦各位达人帮忙,这段代码的可读性我觉得也不是很好,大家将就看下吧,麻烦大家了。全部复制保存成htm就好。

<!DOCTYPE html PUBLIC "-//W3C//DTD X<a href='http://www.pcyyjs.com/webdesign/html/' target='_blank'><u>HTML</u></a> 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=utf-8" />
<title></title>
<style type="text/css">
* { margin:0; padding:0; }
body { margin:20px 0 400px 20px; font:12px Arial; }
h1 { font-size:14px; }
ol { margin:20px; line-height:160%; }
#out {
position:relative;
width:500px;
height:300px;
margin:100px 0 100px 80px;
border:1px solid #369;
overflow:hidden;
}
#content {
width:520px; /*比父容器大20px,将真实滚动条偏出可视区域*/
height:100%;
background:#eee url(http://www.zbw123.com/webmaster/ximenScrollBar/images/bg_michael_jackson.jpg) no-repeat 50%;
overflow:auto;
-moz-user-select:none;
}
#scrollBar,#scrollBarHandle,.scroll_bar_top,.scroll_bar_top_a,.scroll_bar_bottom,.scroll_bar_bottom_a {
background-image:url(http://www.zbw123.com/webmaster/ximenScrollBar/images/un_bg_scrollBar.gif);
}
#scrollBar {
position:absolute;
top:0;
right:0;
z-index:9;
width:14px;
height:100%;
background-repeat:repeat-y;
background-position:-42px 0;
float:left;
}
#scrollBarTop,#scrollBarHandle,#scrollBarBottom {
position:absolute;
left:0;
cursor:default;
}
#scrollBarTop,#scrollBarBottom {
width:100%;
height:14px;
color:#fff;
text-align:center;
}
#scrollBarTop { top:0; }
#scrollBarBottom { bottom:0; }
#scrollBarHandle { width:100%; background-repeat:repeat-y; background-position:-28px 0; }
.scroll_bar_top { background-position:0 0; }
.scroll_bar_top_a { background-position:-14px 0; }
.scroll_bar_bottom { background-position:-56px 0; }
.scroll_bar_bottom_a { background-position:-70px 0; }
</style>
</head>
<body>
<div id="out">
<div id="content">
fsdfs<br />fsdfs<br />11111111<br />fsdfs<br />11111111<br />fsdfs<br />11111111<br />fsdfs<br />11111111<br />fsdfs<br />11111111<br />fsdfs<br />11111111<br />fsdfs<br />11111111<br />fsdfs<br />11111111<br />fsdfs<br />11111111<br />fsdfs<br />11111111<br />fsdfs<br />11111111<br />fsdfs<br />11111111<br />fsdfs<br />11111111<br />fsdfs<br />fsdfs<br />11111111<br />fsdfs<br />11111111<br />fsdfs<br />11111111<br />fsdfs<br />11111111<br />fsdfs<br />11111111<br />fsdfs<br />11111111<br />fsdfs<br />11111111<br />fsdfs<br />11111111<br />fsdfs<br />11111111<br />fsdfs<br />11111111<br />fsdfs<br />11111111<br />fsdfs<br />11111111<br />fsdfs<br />11111111<br />fsdfs<br />fsdfs<br />11111111<br />fsdfs<br />11111111<br />fsdfs<br />11111111<br />fsdfs<br />11111111<br />fsdfs<br />11111111<br />fsdfs<br />11111111<br />fsdfs<br />11111111<br />fsdfs<br />11111111<br />fsdfs<br />11111111<br />fsdfs<br />11111111<br />fsdfs<br />11111111<br />fsdfs<br />11111111<br />fsdfs<br