当前位置:网站首页>Listen to the left width of the browser to calculate the distance
Listen to the left width of the browser to calculate the distance
2022-06-11 07:00:00 【Yu Mei】
problem : Left side tab The column switch needs to be positioned on the left
Scheme 1 : My first thought was relative positioning , But because of the above two tab Switch is a component , So locate it below He'll disappear , It's hiding , Out of document flow , But it also hides , I don't know why . Later, fixed positioning was used , Can appear But it is not adaptive .
Option two : The front page is divided into two boxes . Problems arise : The head will be stretched out
Option three : Listen to the width on the left side of the browser Calculated distance ( Can achieve )
First, give the whole tab Add a dynamic fixed positioning style to the column
<div class="tab" :style="{position: 'fixed',left:flexLT.left,top:'200px'}">
<div :class="[num == index ? 'border_tips' : '']" class="tabbar" v-for="(item,index) in arr" :key="index"
@click="changeIndex(index)">
{
{
item }}
</div>
</div>
And then use getBoundingClientRect() Calculation content Distance of
getBoundingClientRect() This method returns a rectangular object , Contains four properties :left、top、right and bottom. Represents the distance between each edge of the element and the top and left side of the page .
<div class="content" ref="nodeHome">...</div>
var oneLeft = this.$refs.nodeHome.getBoundingClientRect().left;
this.flexLT.left = (oneLeft-160)+'px';
Now it can be fixed on the left side , But it is not adaptive yet , So you need to listen and calculate for the second time
addEventListener() Add event listener
addEventListener(event, function, useCapture)
(1) Parameters event Required , Represents the event being monitored , for example click, resize etc. , Without prefixes on Events .
(2) Parameters function Required , A function that represents the call after event triggering , It can be an externally defined function , It can also be an anonymous function . With no arguments .
(3) Parameters useCapture optional , fill true perhaps false, Used to describe whether the event is bubbling or capturing triggering ,true To capture , Default false Means bubbling .
resize The logical operation to be processed when processing window scaling !
var oneLeft = this.$refs.nodeHome.getBoundingClientRect().left;
this.flexLT.left = (oneLeft-160)+'px';
window.addEventListener('resize', () => {
var dataLeft = this.$refs.nodeHome.getBoundingClientRect().left;
if(dataLeft){
this.flexLT.left = (dataLeft-160)+'px';
}
});
So it can be fixed on the left And adaptive
边栏推荐
- . Net C Foundation (6): namespace - scope with name
- 【Matlab印刷字符识别】OCR印刷字母+数字识别【含源码 1861期】
- VTK-vtkPlane和vtkCutter使用
- Redux learning (II) -- encapsulating the connect function
- Deep Attentive Tracking via Reciprocative Learning
- JVM from getting started to giving up 2: garbage collection
- Start the Nacos server of shell script
- Duality-Gated Mutual Condition Network for RGBT Tracking
- [deploy private warehouse based on harbor] 2 machine preparation
- Promise details
猜你喜欢

Transformer Tracking

常用问题排查工具和分析神器,值得收藏

Won't virtual DOM be available in 2022? Introduction to virtual Dom and complete implementation of diff and patch

Latex various arrows / arrows with text labels / variable length arrows

洛谷P1091合唱队形(最长上升子序列)

saltstack部署lnmp

Redux learning (II) -- encapsulating the connect function

Flutter 约束容器组件

client-go gin的简单整合六-list-watch二(关于Rs与Pod以及Deployment的完善)

你知道IT人才外派服务报价是怎样的么?建议程序员也了解下
随机推荐
Aircraft war from scratch (II) simple development
必读1:格局越大的人,越懂得说话
Esp32 learning notes (49) - esp-wifi-mesh interface use
Difference between byte and bit
News web page display
洛谷P1091合唱队形(最长上升子序列)
网狐游戏服务器房间配置向导服务定制功能页实现
Dynamic import
Completed in May, 22
About daily report plan
Promise details
saltstack部署lnmp
[MATLAB image fusion] particle swarm optimization adaptive multispectral image fusion [including source code phase 004]
Oracle prompt invalid number
Duality-Gated Mutual Condition Network for RGBT Tracking
The difference between arrow function and ordinary function
[deploy private warehouse based on harbor] 4 push image to harbor
Illustrate the principle of one-way linked list and the method of JS to realize linked list [with source code]
Saltstack deployment ZABBIX state file writing
The meaning and research significance of mathematical methodology