jquery 跳转到当前页面指定位置
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
*{padding:0;margin:0;}
.top{ width:100%; height:100px; text-align: center; line-height: 100px;}
.nav{ width:100%; height:100px;}
.nav ul{width:100%; list-style: none;}
.nav ul li { float:left; line-height:100px;
text-align: center; width:25%; background:#0095cd;}
.fixed {position:fixed; top:0px;}
.cont1,.cont2,.cont3,.cont4{width:100%;height:400px; color:#fff;}
.cont1 {background:#00678e; text-align:center; line-height: 400px;}
.cont2 {background:#0F3A56; text-align:center; line-height: 400px;}
.cont3 {background:#33bbee; text-align:center; line-height: 400px;}
.cont4 {background:#7ca1f8; text-align:center; line-height: 400px;}
.footer { background:#68767b; text-align:center;line-height:200px;}
</style>
<script src="style/js/jquery-1.8.3.min.js"></script>
<script>
$(function(){
$(window).scroll(function(){
if ($(window).scrollTop() >= 100) {
$('.nav').addClass('fixed');
} else {
$('.nav').removeClass('fixed');
}
})
var _li = $('.nav').find('li');
_li.each(function(){
var index = $(this).index();
$(this).find('a').click(function(){
var len = index-1;
var numTop = getHeight(len);
$('html,body').animate({scrollTop: numTop + "px"},300);
})
})
})
function getHeight(index) {
var heightall = 0;
for(i=0;i<=index;i++){
heightall += 400;
}
return heightall;
}
</script>
</head>
<body>
<div class="top">这是顶部,高度为100px</div>
<div class="nav">
<ul>
<li><a>first</a></li>
<li><a>scond</a></li>
<li><a>third</a></li>
<li><a>four</a></li>
</ul>
</div>
<div class="cont1">this is content1</div>
<div class="cont2">this is content2</div>
<div class="cont3">this is content3</div>
<div class="cont4">this is content4</div>
<div class="footer">this is footer</div>
</body>
</html>
jquery 跳转到当前页面指定位置的更多相关文章
- html js点击按钮滚动跳转定位到页面指定位置(DIV)的方法代码
一:通过html锚点实现滚动定位到页面指定位置(DIV): 如果我们要点击实现跳转的地方是一个html锚点,也就是点击一个A标签超链接实现跳转,可以把A标签的href属性直接指向跳转指定位置的d ...
- html锚点 点击跳转到页面指定位置
本来是在看阮大神写的ajax教程,突然发现点击目录文字会跳转到相对应的文本内容,于是乎激发了我的兴趣. 这个究竟怎么做的,刚开始看的时候一知半解,找度娘就是:"点击跳转到页面指定位置&quo ...
- ScrollTo:实现平滑滚动到页面指定位置
ScrollTo:实现平滑滚动到页面指定位置 ScrollTo是一款基于jQuery的滚动插件,当点击页面的链接时,可以平滑地滚动到页面指定的位置.适用在一些页面内容比较多,页面长度有好几屏的场合,本 ...
- coolite 获取新的页面链接到当前页面指定位置Panel的运用
如下图所示,点击温州市文成县之前,右边是一片空白,点击后生成新的页面 html运用到了coolite的Panel控件 <Center> <ext:Panel ID="Pan ...
- jQuery跳转到页面指定位置
@参考博客 var t = $("#id").offset().top;// 获取需要跳转到标签的top值 //$(window).scrollTop(t);// 跳转到指定位置 ...
- 锚点/JQ:点击导航跳到网页中的指定位置
今天做了一个简单的功能,页面往下滚动到一定位置,顶部出现一个浮动的导航栏,点击导航栏标签,下面页面跳转到相应的区域.回到顶部,导航栏隐藏. 因为顶部有一个浮动的导航栏,所以跳转到下面页面的时候,总是盖 ...
- 通过href简单实现单击a链接跳转到页面指定位置
在页面中点击a标签后,要使其跳到页面里面相应的地方,方法很简单,就是在a标签里面href中的内容和你要跳到这个区域的id同名即可,例如: <a href="#ppp" tar ...
- HTML实现跳转到页面指定位置
<a href="#page1">跳转到页面1</a> <a href="#page2">跳转到页面2</a> ...
- JQuery插件:ScrollTo平滑滚动到页面指定位置
1.准备jQuery库和scrollTo.js插件. <script type="text/javascript" src="js/jquery.js"& ...
随机推荐
- struts2上传
注意事项:文件名必须是:文件域+FileName,如: // 封装上传文件域的属性 private File uploadImage; // 封装上传文件名的属性 private String upl ...
- 记录一下:chrome上,把网页保存为文件的插件
插件地址: https://chrome.google.com/webstore/detail/full-page-screen-capture/fdpohaocaechififmbbbbbknoal ...
- 用Meta标签控制360浏览器默认极速模式打开自己的网站和正则表达式
在head标签中添加一行代码: <html><head><meta name="renderer" content="webkit|ie-c ...
- PHP建站通过服务器架构及实战的方法
PHP的环境搭建 PHP的帮助使用和配置文件 PHP的Hello World PHP的库函数调用 PHP的Web程序 PHP的函数和面向对象使用 PHP的数据库访问 Nginx安装和配置访问 Word ...
- 超文本标记语言(HTML)
超文本标记语言(HyperText MarkUp Language,HTML) HTML是用来制作网页的标记语言,HTML不需要编译,直接由浏览器解析: HTML文件是一个文本文件,包含了一些HTML ...
- Shuffle'm Up 分类: 函数 POJ 查找 2015-08-09 17:01 6人阅读 评论(0) 收藏
Shuffle'm Up Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7529 Accepted: 3466 Descript ...
- Digital Roots 分类: HDU 2015-06-19 22:56 13人阅读 评论(0) 收藏
Digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- JAVA基础知识之JVM-——URLClassLoader
URLClassLoader是ClassLoader的一个实现类,它既能从本地加载二进制文件类,也可以从远程加载类. 它有两个构造函数, 即 URLClassLoader(URL[] urls),使用 ...
- hiho一下,第115周,FF,EK,DINIC
题目1 : 网络流一·Ford-Fulkerson算法 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho住在P市,P市是一个很大很大的城市,所以也面临着一个 ...
- jQuery 一些小技巧
1. 返回顶部按钮 可以利用 animate 和 scrollTop 来实现返回顶部的动画,而不需要使用其他插件. // Back to top ...