实现拉动右边内容栏左边菜单栏动态变化
2017-10-29 21:18
411 查看
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>位置操作</title> <style> .aa{ background-color: palegreen; width: 30%; float: left; position: fixed; top: 10px; /*left: 20px;*/ } .bb{ width: 70%; float: right; background-color: green; } .cc{ background-color: #dddddd; border-style: solid; border-color: palegreen; font-size: 30px; } .dd{ background-color: aqua; height: 2000px; border-color: black; border-style: dashed; } .ff{ background-color: black; font-size: 20px; color: red; } </style> </head> <body> <!--offsect:标签距离屏幕左上角的距离有多远,距离顶部多远,距离左边多远--> <!--position:标签距离自己的父标签的距离有多远,距离顶部多远,距离左边多远--> <!--heiht:标签的高度,不包括边框--> <!--weight:标签的宽度,不包括边框--> <div class="aa"> <div id="cui1" class="cc">第一章</div> <div id="cui2" class="cc">第二章</div> <div id="cui3" class="cc">第三章</div> </div> <div class="bb"> <div class="dd" sb="cui1">内容一</div> <div class="dd" sb="cui2">内容二</div> <div class="dd" sb="cui3">内容三</div> </div> <script src="jquery-3.2.1.js"></script> <script> $(function () { window.onscroll = function () { // 给整个窗口绑定一个滑轮移动的事件,只要滑轮移动就会触发这个事件 var ws = $(window).scrollTop() // 这个的意思是滑轮移动的距离 $(".bb").children().each(function () { var off = $(this).offset() // 这个的意思是计算每个标签距离顶部和左边的距离 var offtop = off.top h = $(this).height() + offtop // 这个的意思是计算标签距离顶部的高度 // console.log(ws) if(ws>offtop && ws < h){ h = $(this).height() + offtop var x = $(this).attr("sb") var tmp_id = "#" + x $(tmp_id).addClass("ff") }else { h = $(this).height() + offtop var x = $(this).attr("sb") var tmp_id = "#" + x $(tmp_id).removeClass("ff") } }) } }) </script> </body> </html>
相关文章推荐
- ztree实现左边动态生成树右边为内容详情功能
- iframe异步加载实现点击左边菜单加载右边内容实例讲解
- 左边为选项卡,右边为内容,当鼠标滚轮滚动到某一位置时,选项卡样式也相应做变化
- android listview+fragment实现仿京东左边分类名右边分类内容
- 用frameset实现左边导航,右边显示相应内容的布局
- 基于Ajax+div的“左边菜单、右边内容”页面效果实现
- 详情页组件中的内容变化时,价格如何实现动态变化
- JS动态的把左边列表添加到右边的实现代码(可上下移动)
- datagrid中格子和字体颜色根据格子内容动态变化的实现
- JS动态的把左边列表添加到右边的实现代码(可上下移动)
- 用Iframe实现左边TreeView导航,右边显示相应内容的布局
- 基于Ajax+div的“左边菜单、右边内容”页面效果实现
- iframe异步加载实现点击左边菜单加载右边内容实例讲解
- 导航面板[ExtJS4]ExtJS4左边菜单面板收缩展开,右边TabPanel内容动态更新(解决宽度不能自适应问题)
- 左边select内容选择到右边select内容里面的js实现方法(可以多选和全选)
- Axure8.0制作选择左边菜单栏,右边显示相关内容案例
- 左边select内容选择到右边select内容里面的js实现方法(可以多选和全选)
- 在Linux vim编辑器中实现左边目录,右边内容布局的方法。
- 单一静态网页如何实现点击左边菜单在右边展现内容
- 用jq实现点击右边内容实现,左边内容切换、自动切换,当鼠标放上右边li上面,左边内容停止切换。