模板无忧
网页特效
每日更新
|
TOP排行榜
|
Tag标签
|
充值
无忧首页
网页模板
程序模板
建站教程
视频教程
网页特效
图标素材
字体下载
站长工具
站长问答
网页特效
菜单导航
图片特效
文本链接
层和布局
页面背景
表单按钮
日期时间
计算转换
键盘鼠标
浏览器
游戏娱乐
综合其它
常用代码
jQuery特效
Prototype
Ajax/JavaScript
ExtJS
CSS特效
在线编辑器
Mootools
HTML
JS广告代码合集
站长工具
站长常用软件
网站综合查询
Alexa排名查询
Google PR查询
域名Whois查询
网站收录查询
友情链接查询
CSS2中文手册
CSS精简优化工具
网页特效代码
模板无忧
>
网页特效
>
层和布局特效代码
>
收藏
分享
查看评论
层和布局
演示
给一个Div层添加滚动条功能_层和布局特效
查看演示效果
特效Tag:
滚动条
添加
这是一个DIV层,加入了一个滚动条功能,当超出范围的时候便会自动出现,你可以拖动滚动条看看效果哦。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 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" mrc="text/html; charset=gb2312" /> <title>带滚动条的Div</title> <style type="text/css"> body{ font-family: Trebuchet MS, Lucida Sans Unicode, Arial, sans-serif; } p{ margin-top:0px; } #dhtmlgoodies_scrolldiv{ width:530px; height:500px; } #scrolldiv_parentContainer{ width:500px; height:100%; overflow:hidden; border:1px solid #BC8FBD; float:left; position:relative; } #scrolldiv_mrc{ padding: 5px; position:relative; font-family: Trebuchet MS, Lucida Sans Unicode, Arial, sans-serif; font-size: 0.9em; line-height:130%; color: #333; } #scrolldiv_slider{ width:15px; margin-left:2px; height:500px; float:left; } #scrolldiv_scrollbar{ width:15px; height:460px; /* Total height - 40 pixels */ border:1px solid #BC8FBD; position:relative; } #scrolldiv_theScroll{ margin:1px; width:13px; height:13px; background-color:#BC8FBD; position:absolute; top:0px; left:0px; cursor:pointer; } #scrolldiv_scrollUp,#scrolldiv_scrollDown{ width:15px; height:16px; border:1px solid #BC8FBD; color: #BC8FBD; text-align:center; font-size:16px; line-height:16px; cursor:pointer; } #scrolldiv_scrollUp{ margin-bottom:2px; } #scrolldiv_scrollDown{ margin-top:2px; } #scrolldiv_scrollDown span,#scrolldiv_scrollUp span{ font-family: Symbol; } </style> <script type="text/javascript"> var mrcHeight = 0; var visibleContentHeight = 0; var scrollActive = false; /*www.mb5u.com*/ var scrollHandleObj = false; var scrollHandleHeight = false; var scrollbarTop = false; var eventYPos = false; var scrollbuttonActive = false; var scrollbuttonDirection = false; var scrollbuttonSpeed = 2; var scrollTimer = 10; var scrollMoveToActive = false; var scrollMoveToYPosition = false; function scrollDiv_startScroll(e) { if(document.all)e = event; scrollbarTop = document.getElementById('scrolldiv_theScroll').offsetTop; eventYPos = e.clientY; scrollActive = true; } function scrollDiv_stopScroll() { scrollActive = false; scrollbuttonActive = false; scrollMoveToActive = false; } function scrollDiv_scroll(e) { if(!scrollActive)return; if(document.all)e = event; if(e.button!=1 && document.all)return; var topPos = scrollbarTop + e.clientY - eventYPos; if(topPos<0)topPos=0; if(topPos/1>visibleContentHeight-(scrollHandleHeight+4)/1)topPos = visibleContentHeight-(scrollHandleHeight+4); document.getElementById('scrolldiv_theScroll').style.top = topPos + 'px'; document.getElementById('scrolldiv_mrc').style.top = 0 - Math.floor((mrcHeight) * ((topPos)/(visibleContentHeight-scrollHandleHeight)))+'px' } function scrolldiv_scrollMoveToInit(e) { if(document.all)e = event; scrollMoveToActive = true; scrollMoveToYPosition = e.clientY - document.getElementById('scrolldiv_scrollbar').offsetTop; if(document.getElementById('scrolldiv_theScroll').offsetTop/1 > scrollMoveToYPosition) scrollbuttonDirection = scrollbuttonSpeed*-2; else scrollbuttonDirection = scrollbuttonSpeed*2; scrolldiv_scrollMoveTo(); } function scrolldiv_scrollMoveTo() { if(!scrollMoveToActive || scrollActive)return; var topPos = document.getElementById('scrolldiv_theScroll').style.top.replace('px',''); topPos = topPos/1 + scrollbuttonDirection; if(topPos<0){ topPos=0; scrollMoveToActive=false; } if(topPos/1>visibleContentHeight-(scrollHandleHeight+4)/1){ topPos = visibleContentHeight-(scrollHandleHeight+4); scrollMoveToActive=false; } if(scrollbuttonDirection<0 && topPos<scrollMoveToYPosition-scrollHandleHeight/2)return; if(scrollbuttonDirection>0 && topPos>scrollMoveToYPosition-scrollHandleHeight/2)return; document.getElementById('scrolldiv_theScroll').style.top = topPos + 'px'; document.getElementById('scrolldiv_mrc').style.top = 0 - Math.floor((mrcHeight) * ((topPos)/(visibleContentHeight-scrollHandleHeight)))+'px' setTimeout('scrolldiv_scrollMoveTo()',scrollTimer); } function cancelEvent() { return false; } function scrolldiv_scrollButton() { if(this.id=='scrolldiv_scrollDown')scrollbuttonDirection = scrollbuttonSpeed; else scrollbuttonDirection = scrollbuttonSpeed*-1; scrollbuttonActive=true; scrolldiv_scrollButtonScroll(); } function scrolldiv_scrollButtonScroll() { if(!scrollbuttonActive)return; var topPos = document.getElementById('scrolldiv_theScroll').style.top.replace('px',''); topPos = topPos/1 + scrollbuttonDirection; if(topPos<0){ topPos=0; scrollbuttonActive=false; } if(topPos/1>visibleContentHeight-(scrollHandleHeight+4)/1){ topPos = visibleContentHeight-(scrollHandleHeight+4); scrollbuttonActive=false; } document.getElementById('scrolldiv_theScroll').style.top = topPos + 'px'; document.getElementById('scrolldiv_mrc').style.top = 0 - Math.floor((mrcHeight) * ((topPos)/(visibleContentHeight-scrollHandleHeight)))+'px' setTimeout('scrolldiv_scrollButtonScroll()',scrollTimer); } function scrolldiv_scrollButtonStop() { scrollbuttonActive = false; } function scrolldiv_initScroll() { visibleContentHeight = document.getElementById('scrolldiv_scrollbar').offsetHeight ; mrcHeight = document.getElementById('scrolldiv_mrc').offsetHeight - visibleContentHeight; scrollHandleObj = document.getElementById('scrolldiv_theScroll'); scrollHandleHeight = scrollHandleObj.offsetHeight; scrollbarTop = document.getElementById('scrolldiv_scrollbar').offsetTop; document.getElementById('scrolldiv_theScroll').onmousedown = scrollDiv_startScroll; document.body.onmousemove = scrollDiv_scroll; document.getElementById('scrolldiv_scrollbar').onselectstart = cancelEvent; document.getElementById('scrolldiv_theScroll').onmouseup = scrollDiv_stopScroll; if(document.all)document.body.onmouseup = scrollDiv_stopScroll; else document.documentElement.onmouseup = scrollDiv_stopScroll; document.getElementById('scrolldiv_scrollDown').onmousedown = scrolldiv_scrollButton; document.getElementById('scrolldiv_scrollUp').onmousedown = scrolldiv_scrollButton; document.getElementById('scrolldiv_scrollDown').onmouseup = scrolldiv_scrollButtonStop; document.getElementById('scrolldiv_scrollUp').onmouseup = scrolldiv_scrollButtonStop; document.getElementById('scrolldiv_scrollUp').onselectstart = cancelEvent; document.getElementById('scrolldiv_scrollDown').onselectstart = cancelEvent; document.getElementById('scrolldiv_scrollbar').onmousedown = scrolldiv_scrollMoveToInit; } function scrolldiv_setColor(rgbColor) { document.getElementById('scrolldiv_scrollbar').style.borderColor = rgbColor; document.getElementById('scrolldiv_theScroll').style.backgroundColor = rgbColor; document.getElementById('scrolldiv_scrollUp').style.borderColor = rgbColor; document.getElementById('scrolldiv_scrollDown').style.borderColor = rgbColor; document.getElementById('scrolldiv_scrollUp').style.color = rgbColor; document.getElementById('scrolldiv_scrollDown').style.color = rgbColor; document.getElementById('scrolldiv_parentContainer').style.borderColor = rgbColor; } function scrolldiv_setWidth(newWidth) { document.getElementById('dhtmlgoodies_scrolldiv').style.width = newWidth + 'px'; document.getElementById('scrolldiv_parentContainer').style.width = newWidth-30 + 'px'; } function scrolldiv_setHeight(newHeight) { document.getElementById('dhtmlgoodies_scrolldiv').style.height = newHeight + 'px'; document.getElementById('scrolldiv_parentContainer').style.height = newHeight + 'px'; document.getElementById('scrolldiv_slider').style.height = newHeight + 'px'; document.getElementById('scrolldiv_scrollbar').style.height = newHeight-40 + 'px'; } function setSliderBgColor(rgbColor) { document.getElementById('scrolldiv_scrollbar').style.backgroundColor = rgbColor; document.getElementById('scrolldiv_scrollUp').style.backgroundColor = rgbColor; document.getElementById('scrolldiv_scrollDown').style.backgroundColor = rgbColor; } function setContentBgColor(rgbColor) { document.getElementById('scrolldiv_parentContainer').style.backgroundColor = rgbColor; } function setScrollButtonSpeed(newScrollButtonSpeed) { scrollbuttonSpeed = newScrollButtonSpeed; } function setScrollTimer(newInterval) { scrollTimer = newInterval; } </script> </head> <body> <div id="dhtmlgoodies_scrolldiv"> <div id="scrolldiv_parentContainer"> <div id="scrolldiv_mrc">这是一个DIV层,加入了一个滚动条功能,当超出范围的时候便会自动出现,你可以拖动滚动条看看效果哦。<br> </div> </div> <div id="scrolldiv_slider"> <div id="scrolldiv_scrollUp"><img src="/jscss/demoimg/200905/arrow_up.gif"></div> <div id="scrolldiv_scrollbar"> <div id="scrolldiv_theScroll"><span></span></div> </div> <div id="scrolldiv_scrollDown"><img src="/jscss/demoimg/200905/arrow_down.gif"></div> </div> </div> <script type="text/javascript"> scrolldiv_setColor('#317082'); setSliderBgColor('#E2EBED'); setContentBgColor('#FFFFFF'); setScrollButtonSpeed(1); setScrollTimer(5); scrolldiv_setWidth(450); scrolldiv_setHeight(400); scrolldiv_initScroll(); </script> </body> </html>
所属频道:
层和布局特效
/
更新时间:2012-11-19
[收藏]
[报错]
[返回列表]
相关
层和布局特效
:
表格内容排序sortTable
行变成列,列变成行
文本输入限制
拆分单元格
控制表格内的滚动条
颜色交替的表格
JS计算里面有多少个
极酷的表格
会动的表格
可拖动单元格
变色表格
访问表格的每个TD
层和布局特效Rss订阅
特效代码搜索
层和布局特效推荐
CSS隔行换色代码
DIV+CSS一行三列布局的网页
表格行换色代码
动态移动的JavaScript浮动窗口
百度有啊的CSS圆角特效
文本输入限制
jQuery Div拖动+键盘控制综合效果
点击按钮,弹出一个可关闭的层窗口,网页背景变灰
CSS三列高度、中间列自适应代码
CSS+JS表格行选中变色并储存的效果代码
猜你也喜欢看这些
CSS圆角阴影边框的实现
CSS控制图片背景自适应大小【荐】
清爽配色15套
页面载入时的进度条效果的实现
新浪的网页背景特效,可以关闭不显示
登陆FTP网页页面代码
下大雨效果的网页背景,你肯定喜欢
图片与文字半透明效果,鼠标移上不透明
用链接随机改变网页的背景颜色
JavaScript写的炫光波动效果
相关链接:
复制本页链接
|
搜索给一个Div层添加滚动条功能
特效说明:
层和布局模板
-
给一个Div层添加滚动条功能
。