当前位置:网站首页>Anchor location - how to set the distance between the anchor and the top of the page. The anchor is located and offset from the top
Anchor location - how to set the distance between the anchor and the top of the page. The anchor is located and offset from the top
2022-04-23 17:47:00 【Youyoujing】
Anchor is a kind of hyperlink in web page making , Also called named anchor . Named anchors are like quick locators that are hyperlinks within a page , Use is quite common .
Using named anchors, you can set up tags... In your document , These tags are usually placed at or at the top of a specific topic in a document . You can then create links to these named anchors , These links can quickly take visitors to specific locations .
The process of creating a link to a named anchor is divided into two steps . First , Create named anchors , Then create a link to the named anchor .
1. Common anchor
<a href="#aboutmao" > Anchor link </a>
...
<div id="aboutmao"> Anchor jump here </div>
These are the perfect anchor functions , But if my website header Always fixed at the top , This is the anchor link, which used to be the top one header Distance of , Otherwise, the content of a wind linked to the past will be header Occlusion .
Such as this :
The effect we want :
This question uses js The solution is the most convenient :
<a href="javascript:;" class="aboutmao"> About us </a>
<div id="about"> Anchor jump here </div>
<script> $(document).ready(function () {
function topMao(target) {
$('html, body').animate({
scrollTop: $(target).offset().top - $('.topnav').height() // Top fixed navigation }, 500); //130 Is the distance from the anchor point to the top ,500 For execution time return false; } $('.aboutmao').click(function () {
topMao('#about'); }) }) </script>
Click event of anchor , Then get this id Distance from the top of the page , subtract header Height , Last use window.scrollTo Slide directly to the anchor position . Already in ie10+、 firefox 、 Test on Google browser ok.
版权声明
本文为[Youyoujing]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230550531831.html
边栏推荐
- Land cover / use data product download
- Client example analysis of easymodbustcp
- 剑指 Offer 22. 链表中倒数第k个节点-快慢指针
- [binary number] maximum depth of binary tree + maximum depth of n-ary tree
- Construction of functions in C language programming
- 2021 Great Wall Cup WP
- Chrome浏览器的跨域设置----包含新老版本两种设置
- Tell the truth of TS
- 2022年茶艺师(初级)考试模拟100题及模拟考试
- 2021长城杯WP
猜你喜欢
JS get link? The following parameter name or value, according to the URL? Judge the parameters after
Qt error: /usr/bin/ld: cannot find -lGL: No such file or directory
48. 旋转图像
SystemVerilog(六)-变量
92. Reverse linked list II byte skipping high frequency question
The JS timestamp of wechat applet is converted to / 1000 seconds. After six hours and one day, this Friday option calculates the time
stm32入门开发板选野火还是正点原子呢?
Dry goods | how to extract thumbnails quickly?
In JS, t, = > Analysis of
JVM class loading mechanism
随机推荐
48. Rotate image
node中,如何手动实现触发垃圾回收机制
102. 二叉树的层序遍历
JS implementation private attribute
394. String decoding - auxiliary stack
Allowed latency and side output
Gaode map search, drag and drop query address
How to manually implement the mechanism of triggering garbage collection in node
SystemVerilog(六)-变量
Applet learning notes (I)
Index: teach you index from zero basis to proficient use
Element calculation distance and event object
Why do some people say SCM is simple and I have to learn it so hard?
2022年流动式起重机司机国家题库模拟考试平台操作
Commonly used functions -- spineros:: and spineros::)
为什么有些人说单片机简单,我学起来这么吃力?
Router object, route object, declarative navigation, programmed navigation
31. 下一个排列
JVM类加载机制
Summary of common SQL statements