jquery页面滚动显示浮动菜单栏锚点定位效果
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>jQuery页面滚动浮动导航切换代码 - xw素材网</title>
<link rel="stylesheet" type="text/css" href="css/reset.css">
<link rel="stylesheet" type="text/css" href="css/menu.css">
<script type="text/javascript" src="js/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="js/menu.js"></script>
</head>
<body>
<div id="menu">
<ul>
<li><a href="#item1" class="cur">One</a></li>
<li><a href="#item2">Two</a></li>
<li><a href="#item3">Three</a></li>
<li><a href="#item4">Four</a></li>
<li><a href="#item5">Fir</a></li>
</ul>
</div>
<div id="content">
<div class="item" id="item1">
<h1>1F</h1>
<div style="text-align:center;margin:50px 0; font:normal 14px/24px 'MicroSoft YaHei';">
<p>适用浏览器:IE8、360、FireFox、Chrome、Safari、Opera、傲游、搜狗、世界之窗.</p>
<p>来源:<a href="http://www.xwcms.net/" target="_blank">xw素材网</a></p>
</div>
</div>
<div class="item" id="item2">
<h1>2F</h1>
</div>
<div class="item" id="item3">
<h1>3F</h1>
</div>
<div class="item" id="item4">
<h1>4F</h1>
</div>
<div class="item" id="item5">
<h1>5F</h1>
</div>
</div>
</body>
</html>
menu.js
$(document).ready(function(){
$(window).scroll(function(){
var top = $(document).scrollTop(); //定义变量,获取滚动条的高度
var menu = $("#menu"); //定义变量,抓取#menu
var items = $("#content").find(".item"); //定义变量,查找.item
var curId = ""; //定义变量,当前所在的楼层item #id
items.each(function(){
var m = $(this); //定义变量,获取当前类
var itemsTop = m.offset().top; //定义变量,获取当前类的top偏移量
if(top > itemsTop-100){
curId = "#" + m.attr("id");
}else{
return false;
}
});
//给相应的楼层设置cur,取消其他楼层的cur
var curLink = menu.find(".cur");
if( curId && curLink.attr("href") != curId ){
curLink.removeClass("cur");
menu.find( "[href=" + curId + "]" ).addClass("cur");
}
// console.log(top);
});
});
menu.css
#content{width: 100%;height: auto; margin: 0 auto;}
#content div{width: 100%; height: 868px; margin: 0 auto;}
#content div#item1{background-color: #00ff00}
#content div#item2{background-color: #279756}
#content div#item3{background-color: #2ce3e5}
#content div#item4{background-color: #5e57e7}
#content div#item5{background-color: #ca61ae}
#content div h1{font-size: 36px; color: #fff;}
#menu{width: 88px;height: auto; position: fixed;top: 50%;right: 15px;margin-top: -135px;}
#menu ul{display: block;list-style: none}
#menu ul li a{width: 88px; height: 54px; line-height: 54px; text-align: center;background-color: #fff;color: #32c96a;display: block}
#menu ul li a:hover,#menu ul li a.cur{background-color: #32c92a;color: #fff;}
reset.css
*[hidefocus]{outline:none;}
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td{padding:;margin:;}
fieldset,img,html,body,iframe{border:;}
table{border-collapse:collapse;border-spacing:;}
li{list-style:none;}
h1,h2,h3,h4,h5,h6{font-weight:bold;font-size:100%;}
caption,th{font-weight:normal;font-style:normal;text-align:left;}
em,strong{font-weight:bold;font-style:normal;}
body,textarea,select,input{font-family:helvetica,arial,simsun,sans-serif;font-size:14px;color:#000;}
body{background-color:#fff;}
a,button{cursor:pointer;}
a{text-decoration:none;color:#000; outline: none;}
a:hover{text-decoration:none;}
html,body{width:100%;height:100%;}
html{overflow:auto;overflow-y:scroll;}
jquery页面滚动显示浮动菜单栏锚点定位效果的更多相关文章
- jQuery页面滚动右侧浮动导航切换
体验效果:http://hovertree.com/texiao/jquery/49/ 效果图: 代码如下: <!DOCTYPE html> <html> <head&g ...
- Jquery实现滚动显示欢迎字幕效果
Jquery控制滚动显示欢迎字幕: 参考代码: <!DOCTYPE html> <html> <head> <title>Colin Marquee W ...
- Jquery控制滚动显示欢迎字幕v2
Jquery控制滚动显示欢迎字幕v2: 之前做的那个比较适合测试环境,但要套入到网站中,有两个按钮在那摆着,还是不太好看.后面对代码进行了修改,如下: 参考代码: <html> <h ...
- jQuery页面滚动监听事件及高级效果插件
jQuery页面滚动监听事件及高级效果插件 1. One Page scroll (只适用于上下焦点图)http://www.thepetedesign.com/demos/onepage_scrol ...
- scrollReveal.js – 页面滚动显示动画JS
简介 和 WOW.js 一样,scrollReveal.js 也是一款页面滚动显示动画的 JavaScript ,能让页面更加有趣,更吸引用户眼球.不同的是 WOW.js 的动画只播放一次,而 ...
- jquery页面滚动到指定id
//jquery页面滚动到指定id $body = (window.opera) ? (document.compatMode == "CSS1Compat" ? $('html ...
- WOW.js – 在页面滚动时展现动感的元素动画效果
在一些网页上,当你滚动页面的时候会看到各式各样的元素动画效果,非常动感.WOW.js 就是一款帮助你实现这种 CSS 动画效果的插件,很容易定制,你可以改变动画设置喜欢的风格.延迟.长度.偏移和迭代等 ...
- jquery 页面滚动到底部自动加载插件集合
很多社交网站都使用无限滚动的翻页技术来提高用户体验,当你页面滑到列表底部时候无需点击就自动加载更多的内容.下面为你推荐 10 个 jQuery 的无限滚动的插件: 1. jQuery ScrollPa ...
- jquery 上下滚动显示隐藏
function scroll(fn) { var beforeScrollTop = document.body.scrollTop, fn = fn || function() {}; win ...
随机推荐
- python 使用pyinstaller,pywin32打包.py成.exe应用程序
想将编写的Python代码在别人的电脑上运行,由于没有配置python的环境,这就有了困难.搜索学习了下,借助一定的工具可以将python程序的.py文件打包为exe文件,当然有多种方法,本文介绍的方 ...
- 05、Windows Store app 的图片裁切(更新)
在 Win Phone Silverlight api 中,有一个 PhotoChooserTask 选择器,指定宽.高属性,在选择图片的时候, 可以进行裁切,代码: PhotoChooserTask ...
- Windows Phone 推送通知的第四类推送
在 MSDN 文档有关 Windows Phone 推送通知 有关推送的内容包含 Tile.Toast.Raw 这三种通知.这三种通知 的方式类似,运用的场合不同,这里不再赘述,它们的运行原理类似: ...
- 检查是否是移动端(Mobile)、ipad、iphone、微信、QQ等
<script type="text/javascript"> //判断访问终端 var browser={ versions:function(){ var u = ...
- error: no matching function for call to 'Ui::GoToCellDialog::setupUi(QDialog*&)' ui.setupUi(dialog); ^
环境:Qt5.3 参考书是:C++ GUI Qt4编程 问题描述: 按照书中的例子2-2做,编译时遇到的问题,从字面意思看是没有匹配的函数可用,UI::GotoCellDialog类是自动生成的,所以 ...
- echarts 百度图表
手册说明 http://echarts.baidu.com/option.html 3.0版本加了很多新属性可以看以上链接 此文用的3.x版本 第一步 引入 <script src=" ...
- java ssm框架入门(二)添加语言滤器
使用过滤器是在web.xml中使用filter,以下是码过滤器,过滤所有资源的使用 web.xml <filter> <filter-name>setCharactor< ...
- Unix系统编程()信号类型和默认行为
信号类型和默认行为 就是讲了有多少个信号类型 好多啊,后面用到了再看...
- Python之美[从菜鸟到高手]--NotImplemented小析
今天写代码时无意碰到NotImplemented,我一愣.难道是NotImplementedError的胞弟,所以略微研究了一下. NotImplemented故名思议.就是"未实现&quo ...
- CSS(七):浮动
一.float属性取值:left:左浮动right:右浮动none:不浮动 先看下面的一个例子: <!DOCTYPE html> <html lang="en"& ...