jQuery侧边栏固定
来源:互联网 发布:里约热内卢 知乎 编辑:程序博客网 时间:2024/05/17 08:39
<!DOCTYPE html><html><head><meta charset="UTF-8"><title></title><style>#top_head {width: 100%;height: 253px;background: gray;}#middle_right_list {width: 70%;height: 1800px;background: #0000FF;float: left;}#middle_left {width: 30%;height: 300px;float: left;}#middle_left_list {width: 100%;height: 300px;background: #003580;background-image: url(../../CS/布局属性全接触/img/1.jpg);/*transition: top .03s ease-in;*/}#middle_content {position: relative;}#middle_content:after {content: '';display: block;clear: both;overflow: hidden;}#foot {width: 100%;height: 200px;background: #004099;}body,html{padding: 0;margin: 0;}</style><script>function getByID(idname) {var ob = document.getElementById(idname);return ob;}window.addEventListener('scroll', function() {//获取滚动高度var scrolHight = document.body.scrollTop;var middle_left = getByID('middle_left_list');var contentHeight = getByID('middle_right_list').offsetHeight - middle_left.offsetHeight;console.log(contentHeight);if (scrolHight > 253 && scrolHight < (contentHeight + 253)) {//改变CSSmiddle_left.style.position = 'absolute';middle_left.style.top = (scrolHight - 253) + 'px';middle_left.style.left = '0px';middle_left.style.width = '30%';} else if (scrolHight <= 253) {middle_left.style.position = 'static';middle_left.style.width = '100%';}})//window.onscroll = function() {////}</script></head><body><div class="container"><div id="top_head">头部</div><div id="middle_content"><div id="middle_left"><div id="middle_left_list">左菜单</div></div><div id="middle_right_list">课程列表</div></div><div id="foot">底部</div></div></body></html>
jQuery实现:
<!DOCTYPE html><html><head><meta charset="UTF-8"><title></title><style>#top_head {width: 100%;height: 253px;background: gray;}#middle_right_list {width: 70%;height: 1800px;background: #0000FF;float: left;}#middle_left {width: 30%;height: 300px;float: left;}#middle_left_list {width: 100%;height: 300px;background: #003580;background-image: url(../../CS/布局属性全接触/img/1.jpg);/*transition: top .03s ease-in;*/}#middle_content {position: relative;}#middle_content:after {content: '';display: block;clear: both;overflow: hidden;}#foot {width: 100%;height: 200px;background: #004099;}body,html {padding: 0;margin: 0;}</style><script src="../jquery-2.2.4.min.js"></script><script>$(window).scroll(function() {var scrollHeight = $(window).scrollTop();var topHeight = $('#top_head').height();var slideHeight = $('#middle_left').height();var contentHeight = $('#middle_content').height() - slideHeight;console.log(scrollHeight);console.log('max:'+ (contentHeight + topHeight));if(scrollHeight > contentHeight + topHeight) {scrollHeight = contentHeight + topHeight;}if (scrollHeight > topHeight && scrollHeight <= contentHeight + topHeight) {$('#middle_left_list').css({"position": "absolute","top": scrollHeight - topHeight + 'px',"left": 0,"width": '30%'});} else if (scrollHeight <= topHeight) {$('#middle_left_list').css({"position": "absolute","top": 0,"left": 0,"width": '30%'});}})</script></head><body><div class="container"><div id="top_head">头部</div><div id="middle_content"><div id="middle_left"><div id="middle_left_list">左菜单</div></div><div id="middle_right_list">课程列表</div></div><div id="foot">底部</div></div></body></html>
0 0
- jQuery侧边栏固定
- jQuery固定侧边栏导航插件
- jquery+css实现滚动固定侧边栏
- 侧边固定导航栏
- 网站侧边栏固定
- jquery侧边栏效果
- JQuery侧边栏实现
- 固定浮动侧边栏(SmartFloat)
- JS固定侧边栏教程总结
- jquery编写侧边导航栏
- 侧边固定悬浮导航
- 图片悬浮网页侧边栏固定不动代码
- ubuntu去掉侧边栏和桌面的固定图标
- FLEX实现两侧边栏固定中间自适应布局
- jquery实现侧边栏左右伸缩
- jquery侧边栏(仿购物网站)
- 侧边栏
- 侧边栏
- jQuery 自定义扩展,与$冲突处理
- linux相关命令
- jQuery 动态添加瀑布流
- jQuery 实现菜单
- jQuery 菜单项切换
- jQuery侧边栏固定
- Linux系统主要文件夹作用及分区
- jQueryUI之交互
- .gitignore上传无效问题解决
- jQueryUI 之控件们
- jQueryMobile控件之复选框
- jQueryMobile控件之按钮
- SSH框架之Struts的struts-default.xml配置文件
- jQueryMobile控件之页面切换