当前位置:网站首页>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
边栏推荐
- 402. 移掉 K 位数字-贪心
- 470. 用 Rand7() 实现 Rand10()
- 云原生虚拟化:基于 Kubevirt 构建边缘计算实例
- Learning record of uni app dark horse yougou project (Part 2)
- 开源按键组件Multi_Button的使用,含测试工程
- QT modification UI does not take effect
- 双闭环直流调速系统matlab/simulink仿真
- Gets the time range of the current week
- In embedded system, must the program code in flash be moved to ram to run?
- 92. 反转链表 II-字节跳动高频题
猜你喜欢
Allowed latency and side output
极致体验,揭晓抖音背后的音视频技术
Applet learning notes (I)
01 - get to know the advantages of sketch sketch
C1小笔记【任务训练篇二】
Error in created hook: "referenceerror:" promise "undefined“
【Appium】通过设计关键字驱动文件来编写脚本
Halo 开源项目学习(二):实体类与数据表
关于gcc输出typeid完整名的方法
STM32 entry development board choose wildfire or punctual atom?
随机推荐
Write a regular
开源按键组件Multi_Button的使用,含测试工程
Sword finger offer 03 Duplicate number in array
【Appium】通过设计关键字驱动文件来编写脚本
Advantages and disadvantages of several note taking software
102. 二叉树的层序遍历
[appium] write scripts by designing Keyword Driven files
440. 字典序的第K小数字(困难)-字典树-数节点-字节跳动高频题
Future 用法详解
PC电脑使用无线网卡连接上手机热点,为什么不能上网
2021 Great Wall Cup WP
41. The first missing positive number
Use of five routing guards
Cross domain settings of Chrome browser -- including new and old versions
Applet learning notes (I)
高德地图搜索、拖拽 查询地址
2021长城杯WP
练习:求偶数和、阈值分割和求差( list 对象的两个基础小题)
Qt error: /usr/bin/ld: cannot find -lGL: No such file or directory
JS parsing and execution process