当前位置:网站首页>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
边栏推荐
- 【Matlab印刷字符识别】OCR印刷字母+数字识别【含源码 1861期】
- saltstack的常用模块
- . Net C Foundation (6): namespace - scope with name
- 563. slope of binary tree
- Shell脚本之启动Nacos服务端
- Wan Zichang's article shows you promise
- [matlab WSN communication] a_ Star improved leach multi hop transmission protocol [including source code phase 487]
- 538. convert binary search tree to cumulative tree
- [Xunwei dry goods] opencv test of Godson 2k1000 development board
- Leetcode-104. Maximum Depth of Binary Tree
猜你喜欢
随机推荐
[deploy private warehouse based on harbor] 4 push image to harbor
Required reading 1: the larger the pattern, the better they know how to speak
saltstack部署lnmp
搜狐员工遭遇工资补助诈骗 黑产与灰产有何区别 又要如何溯源?
[deploy private warehouse based on harbor] 2 machine preparation
Web API、DOM
Start the Nacos server of shell script
Matplotlib,设置坐标刻度大小,字体/设置图例大小及字体/设置纵横坐标名称及字体及大小
June training (day 11) - matrix
Starting from scratch (V) realize bullet positioning and animation
关于 QtCreator的设计器QtDesigner完全无法正常拽托控件 的解决方法
saltstack的常用模块
Heartless sword Chinese English bilingual poem 001 Love
[Xunwei dry goods] opencv test of Godson 2k1000 development board
SQL query. Only the column name is displayed but not the data
通过 Ingress 进行灰度发布
1266_FreeRTOS调度器启动代码实现分析
Transformer Tracking
Promise. All capture error
网狐游戏服务器房间配置向导服务定制功能页实现
![[]==! []](/img/65/ab724c74b080da319ed5c01c93fdb7.png)







