jq点击导航页面滑动到对应内容demo效果示例(整理)
示例 页面 内容 效果 整理 点击 导航 Demo
2023-09-14 09:13:42 时间
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script>
<title>jq点击导航页面滑动到对应内容</title>
<style>
* {
margin: 0;
padding: 0;
}
.div {
position: fixed;
top: 0;
left: 500px;
}
ul {
list-style: none;
}
ul li {
width: 80px;
height: 50px;
line-height: 50px;
text-align: center;
display: inline-block;
cursor: pointer;
background: gray;
}
#hd1 {
height: 100px;
width: 100%;
}
#hd2 {
height: 500px;
width: 100%;
}
#hd3 {
height: 800px;
width: 100%;
}
#hd4 {
height: 1000px;
width: 100%;
}
#hd5 {
height: 1500px;
width: 100%;
}
</style>
</head>
<body>
<div class="div">
<ul>
<li onclick="click_scroll()">导航1</li>
<li onclick="click_scroll2()">导航2</li>
<li onclick="click_scroll3()">导航3</li>
<li onclick="click_scroll4()">导航4</li>
<li onclick="click_scroll5()">导航5</li>
</ul>
</div>
<div>
<div id="hd1" class="section">
<div>内容一</div>
</div>
<div id="hd2" class="section">
<div>内容二</div>
</div>
<div id="hd3" class="section">
<div>内容三</div>
</div>
<div id="hd4" class="section">
<div>内容四</div>
</div>
<div id="hd5" class="section">
<div>内容五</div>
</div>
</div>
<script type="text/javascript">
//500 控制点击滚动条向下滑动的速度
function click_scroll() {
var scroll_offset = $("#hd1").offset().top;
$("body,html").animate({
scrollTop: scroll_offset
}, 500);
}
function click_scroll2() {
var scroll_offset = $("#hd2").offset().top;
$("body,html").animate({
scrollTop: scroll_offset
}, 500);
}
function click_scroll3() {
var scroll_offset = $("#hd3").offset().top;
$("body,html").animate({
scrollTop: scroll_offset
}, 500);
}
function click_scroll4() {
var scroll_offset = $("#hd4").offset().top;
$("body,html").animate({
scrollTop: scroll_offset
}, 500);
}
function click_scroll5() {
var scroll_offset = $("#hd5").offset().top;
$("body,html").animate({
scrollTop: scroll_offset
}, 500);
}
</script>
</body>
</html>
相关文章
- jmx完整示例
- Velocity魔法堂系列一:入门示例
- 读书笔记--SQL必知必会--常用MySQL(MariaDB)命令及示例
- 从0到1学习使用OAK——面部信息识别示例
- Linux crontab定时任务示例
- Hadoop大数据--Mapreduce编程规范及入门示例
- 一天JavaScript示例-判定web页面的区域
- Android自己的自动化测试Monkeyrunner和用法示例
- 华为运营商级路由器配置示例 | L3VdPdNdv4 HoVdPdNd over SRv6 BE拼接SRv6 BE
- 007:vue+openlayers加载ArcGIS地图示例
- js:二级联动示例
- Python Flask JinJa2 语法介绍与示例讲解
- Python异或运算符示例
- Redis的pubsub机制及简单的python示例