网站首页 > 知识剖析 正文
在设计网页中,锚点滚动是不可或缺的,现在分享给大家,好好看看。
jq代码
为了好复制,插入整个demo源码
<!DOCTYPE html>
<html>
<head>
<metacharset="UTF-8">
<metaname="viewport"content="width=device-width, initial-scale=1.0">
<metahttp-equiv="X-UA-Compatible"content="ie=edge">
<title>js锚点滚动效果</title>
<style>
ul>li{float: left;margin: 10px ;}
.clearfix:after{display:block;clear:both;content:"";visibility:hidden;height:0}
.clearfix{zoom:1}
.step{width:80%;height:1300px;border:10pxsolidred;margin:0auto;}
</style>
</head>
<body>
<ulclass="clearfix">
<li><ahref="#step1">#step1</a></li>
<li><ahref="#step2">#step2</a></li>
<li><ahref="#step3">#step3</a></li>
</ul>
<div>
<divid="step1"class="step">step1</div>
<divid="step2"class="step">step2</div>
<divid="step3"class="step">step3</div>
</div>
</body>
<scriptsrc="http://libs.baidu.com/jquery/1.8.3/jquery.min.js"></script>
<script>
//页面锚点滚动js
$('a[href*=#],area[href*=#]').click(function {
if (location.pathname.replace(/^//, '') ==this.pathname.replace(/^//, '') &&location.hostname ==this.hostname) {
var$target=$(this.hash);
$target=$target.length &&$target||$('[name='+this.hash.slice(1) +']');
if ($target.length) {
vartargetOffset=$target.offset.top;
$('html,body').animate({
scrollTop: targetOffset
},
1000);
returnfalse;
}
}
});
//页面锚点滚动js结束
</script>
</html>
ps:希望喜欢我的朋友点赞,关注,转发一下。
网站开发,程序设计,UI等相关问题,编程技巧以及其他你想向我问的问题,来者不拒。
- 上一篇: 【HTML】概念和基本标签
- 下一篇: 简析html5、html的13条区别
猜你喜欢
- 2025-01-01 到底什么是HTML、HTML5
- 2025-01-01 我理解的网站产品经理之四:网站产品前端姿势
- 2025-01-01 如何刷新当前的页面
- 2025-01-01 HTML offsetHeight 属性用法详解
- 2025-01-01 html和css实现页面
- 2025-01-01 HTML和xml有哪些区别?
- 2025-01-01 WP主题开发14:怎样添加wordpress主题trans的文章列表页模板?
- 2025-01-01 手把手教你HTML5实现定位当前地理位置
- 2025-01-01 Spring Boot集成itext实现html生成PDF功能
- 2025-01-01 web前端HTML教程-body部分
- 最近发表
- 标签列表
-
- xml (46)
- css animation (57)
- array_slice (60)
- htmlspecialchars (54)
- position: absolute (54)
- datediff函数 (47)
- array_pop (49)
- jsmap (52)
- toggleclass (43)
- console.time (63)
- .sql (41)
- ahref (40)
- js json.parse (59)
- html复选框 (60)
- css 透明 (44)
- css 颜色 (47)
- php replace (41)
- css nth-child (48)
- min-height (40)
- xml schema (44)
- css 最后一个元素 (46)
- location.origin (44)
- table border (49)
- html tr (40)
- video controls (49)