| 项目搜索 |
| |
|
代码片段库:
查看代码片段
浏览
| 提交新的代码片段
| 创建代码包
滚动的导航条
|
类型:
Full Script |
类别:
HTML Manipulation
|
许可证:
GNU General Public License |
语言:
JavaScript
|
描述:
类似IE的滚动导航条,对于大段文字内容显示时是非常适用的 来源:http://www.baron.com.cn
|
该代码片段的版本系列:
片段ID |
下载版本 |
提交时间 |
提交人 |
删除 |
4799 | 1.0 | 2003-10-24 04:35 | cbd001 | |
点击"下载版本"来下载该代码片段.
最新版本的代码片段: 1.0
脚本说明:
第一步:把如下代码加入<body>区域中
<SCRIPT language=JavaScript>
// Known bugs 10.01.2001
// Not able to remove browser-scrollbar in netscape 6, if the span "content" is heigher than browserwindow... :-(
// If ie4.5 mac, please press apple-t to remove sidebar, otherwise everything is pushed 20px to the right...
// Touch me here :-)
var upH = 13; // Height of up-arrow
var upW = 13; // Width of up-arrow
var downH = 13; // Height of down-arrow
var downW = 13; // Width of down-arrow
var dragH = 26; // Height of scrollbar
var dragW = 13; // Width of scrollbar
var scrollH = 138; // Height of scrollbar
var speed = 4; // Scroll speed
// And now... go to the bottom of the page...
// Browser detection
var dom = document.getElementById ? true:false;
var nn4 = document.layers ? true:false;
var ie4 = document.all ? true:false;
var mouseY; // Mouse Y position onclick
var mouseX; // Mouse X position onclick
var clickUp = false; // If click on up-arrow
var clickDown = false; // If click on down-arrow
var clickDrag = false; // If click on scrollbar
var clickAbove = false; // If click above scrollbar
var clickBelow = false; // If click below scrollbar
var timer = setTimeout("",500); // Repeat variable
var upL; // Up-arrow X
var upT; // Up-arrow Y
var downL; // Down-arrow X
var downT; // Down-arrow Y
var dragL; // Scrollbar X
var dragT; // Scrollbar Y
var rulerL; // Ruler X
var rulerT; // Ruler Y
var contentT; // Content layer Y;
var contentH; // Content height
var contentClipH; // Content clip height
var scrollLength; // Number of pixels scrollbar should move
var startY; // Keeps track of offset between mouse and span
// Mousedown
function down(e){
if((document.layers && e.which!=1) || (document.all && event.button!=1)) return true; // Enables the right mousebutton
getMouse(e);
startY = (mouseY - dragT);
// If click on up-arrow
if(mouseX >= upL && (mouseX <= (upL + upW)) && mouseY >= upT && (mouseY <= (upT + upH))){
clickUp = true;
return scrollUp();
}
// Else if click on down-arrow
else if(mouseX >= downL && (mouseX <= (downL + downW)) && mouseY >= downT && (mouseY <= (downT + downH))){
clickDown = true;
return scrollDown();
}
// Else if click on scrollbar
else if(mouseX >= dragL && (mouseX <= (dragL + dragW)) && mouseY >= dragT && (mouseY <= (dragT + dragH))){
clickDrag = true;
return false;
}
else if(mouseX >= dragL && (mouseX <= (dragL + dragW)) && mouseY >= rulerT && (mouseY <= (rulerT + scrollH))){
// If click above drag
if(mouseY < dragT){
clickAbove = true;
clickUp = true;
return scrollUp();
}
// Else click below drag
else{
clickBelow = true;
clickDown = true;
return scrollDown();
}
}
// If no scrolling is to take place
else{
return true;
}
}
// Drag function
function move(e){
if(clickDrag){
getMouse(e);
dragT = (mouseY - startY);
if(dragT < (rulerT))
dragT = rulerT;
if(dragT > (rulerT + scrollH - dragH))
dragT = (rulerT + scrollH - dragH);
contentT = ((dragT - rulerT)*(1/scrollLength));
contentT = eval('-' + contentT);
moveTo();
// So ie-pc doesn't select gifs
if(ie4)
return false;
}
}
function up(){
clearTimeout(timer);
// Resetting variables
clickUp = false;
clickDown = false;
clickDrag = false;
clickAbove = false;
clickBelow = false;
return true;
}
// Reads content layer top
function getT(){
if(ie4)
contentT = document.all.content.style.pixelTop;
else if(nn4)
contentT = document.contentClip.document.content.top;
else if(dom)
contentT = parseInt(document.getElementById("content").style.top);
}
// Reads mouse X and Y coordinates
function getMouse(e){
if(ie4){
mouseY = event.clientY;
mouseX = event.clientX;
}
else if(nn4 || dom){
mouseY = e.pageY;
mouseX = e.pageX;
}
}
// Moves the layer
function moveTo(){
if(ie4){
document.all.content.style.top = contentT;
document.all.ruler.style.top = dragT;
document.all.drag.style.top = dragT;
}
else if(nn4){
document.contentClip.document.content.top = contentT;
document.ruler.top = dragT;
document.drag.top = dragT;
}
else if(dom){
document.getElementById("content").style.top = contentT + "px";
document.getElementById("drag").style.top = dragT + "px";
document.getElementById("ruler").style.top = dragT + "px";
}
}
// Scrolls up
function scrollUp(){
getT();
if(clickAbove){
if(dragT <= (mouseY-(dragH/2)))
return up();
}
if(clickUp){
if(contentT < 0){
dragT = dragT - (speed*scrollLength);
if(dragT < (rulerT))
dragT = rulerT;
contentT = contentT + speed;
if(contentT > 0)
contentT = 0;
moveTo();
timer = setTimeout("scrollUp()",25);
}
}
return false;
}
// Scrolls down
function scrollDown(){
getT();
if(clickBelow){
if(dragT >= (mouseY-(dragH/2)))
return up();
}
if(clickDown){
if(contentT > -(contentH - contentClipH)){
dragT = dragT + (speed*scrollLength);
if(dragT > (rulerT + scrollH - dragH))
dragT = (rulerT + scrollH - dragH);
contentT = contentT - speed;
if(contentT < -(contentH - contentClipH))
contentT = -(contentH - contentClipH);
moveTo();
timer = setTimeout("scrollDown()",25);
}
}
return false;
}
// reloads page to position the layers again
function reloadPage(){
location.reload();
}
// Preload
function eventLoader(){
if(ie4){
// Up-arrow X and Y variables
upL = document.all.up.style.pixelLeft;
upT = document.all.up.style.pixelTop;
// Down-arrow X and Y variables
downL = document.all.down.style.pixelLeft;
downT = document.all.down.style.pixelTop;
// Scrollbar X and Y variables
dragL = document.all.drag.style.pixelLeft;
dragT = document.all.drag.style.pixelTop;
// Ruler Y variable
rulerT = document.all.ruler.style.pixelTop;
// Height of content layer and clip layer
contentH = document.all.content.offsetHeight;
contentClipH = document.all.contentClip.offsetHeight;
}
else if(nn4){
// Up-arrow X and Y variables
upL = document.up.left;
upT = document.up.top;
// Down-arrow X and Y variables
downL = document.down.left;
downT = document.down.top;
// Scrollbar X and Y variables
dragL = document.drag.left;
dragT = document.drag.top;
// Ruler Y variable
rulerT = document.ruler.top;
// Height of content layer and clip layer
contentH = document.contentClip.document.content.clip.bottom;
contentClipH = document.contentClip.clip.bottom;
}
else if(dom){
// Up-arrow X and Y variables
upL = parseInt(document.getElementById("up").style.left);
upT = parseInt(document.getElementById("up").style.top);
// Down-arrow X and Y variables
downL = parseInt(document.getElementById("down").style.left);
downT = parseInt(document.getElementById("down").style.top);
// Scrollbar X and Y variables
dragL = parseInt(document.getElementById("drag").style.left);
dragT = parseInt(document.getElementById("drag").style.top);
// Ruler Y variable
rulerT = parseInt(document.getElementById("ruler").style.top);
// Height of content layer and clip layer
contentH = document.getElementById("content").offsetHeight;
contentClipH = document.getElementById("contentClip").offsetHeight;
document.getElementById("content").style.top = 0 + "px";
}
// Number of pixels scrollbar should move
scrollLength = ((scrollH-dragH)/(contentH-contentClipH));
// Initializes event capturing
if(nn4){
document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP)
window.onresize = reloadPage;
}
document.onmousedown = down;
document.onmousemove = move;
document.onmouseup = up;
}
</SCRIPT>
<STYLE type=text/css>
#content {
POSITION: absolute
}
</STYLE>
<SPAN
id=up
style="Z-INDEX: 1; LEFT: 719px; WIDTH: 1px; POSITION: absolute; TOP: 161px; HEIGHT: 1px"><IMG
src="up_001.gif" border=0></SPAN>
<SPAN id=down
style="Z-INDEX: 2; LEFT: 719px; WIDTH: 1px; POSITION: absolute; TOP: 299px; HEIGHT: 1px"><IMG
src="down_001.gif" border=0></SPAN>
<SPAN
id=drag
style="Z-INDEX: 3; LEFT: 719px; WIDTH: 13px; POSITION: absolute; TOP: 174px; HEIGHT: 100px"><IMG
src="drag_001.gif" border=0></SPAN>
<SPAN
id=ruler
style="Z-INDEX: 4; LEFT: 719px; WIDTH: 13px; POSITION: absolute; TOP: 174px; HEIGHT: 100px"></SPAN>
<SPAN
id=contentClip
style="Z-INDEX: 5; LEFT: 470px; VISIBILITY: visible; OVERFLOW: hidden; WIDTH: 240px; CLIP: rect(0px 240px 151px 0px); POSITION: absolute; TOP: 161px; HEIGHT: 151px"><SPAN
id=content>
<DIV class=news>香港政府财政司司长梁锦松,不久前公布了他就任财政司长后的第一份财政预算案。面对前所未有的经济困难,梁锦松分析了形势,理清了思路,提出了复苏经济、推动发展的方略,并在政府财政赤字庞大的情况下,提出多项纾解民困的新措施。从新的预算案,广大市民既看到了政府着眼香港经济长期繁荣的战略蓝图,更感受到了政府倾听民意、体恤民困、“急民所急”的殷殷真情。而梁锦松在宣读预算案时,以电视剧《狮子山下》主题曲的歌词作为结束语,更表达了政府与全体市民团结拼搏再创辉煌的深切期望与坚定信心。梁锦松的激情,立即得到广大市民的积极回应。不少人重新唱起了这首老歌:“放开彼此心中矛盾,理想一起去追,同舟人,誓相随,无畏更无惧。同处海角天边,携手踏平崎岖,我们大家用艰辛努力,写下那不朽香江名句。”二十多年前,港人们就是唱着这首歌,戮力同心,紧抓机遇,劈波斩浪,携手推动经济转型、进而实现腾飞的。一大批工商才俊,也是在这种团结向上、拼搏奋进的氛围里脱颖而出的。但是,由于较长时间的顺利发展,人们艰苦奋斗的劲头逐渐淡漠;更由于近年来少数政客的恶意挑唆、一味唱衰,香港一度人心涣散,怨气、戾气弥漫。
</DIV></SPAN></SPAN>
第二步:把<body>中的代码改为:
<body onload=eventLoader();>
如果您修改了一个代码片段并且觉得很应该让别人共享,您可以把这作为这个代码片段的最新版本提交上来. |
|