input 组件层级高 漂浮在 fixed 元素之上 解决方案

<!--
	
	问题描述 input 组件层级高 漂浮在 fixed 元素之上, fixed元素设置z-index再高也覆盖不了input 
 	思路
 		
 		input 和 view 元素  设置一样的css样式 设置为绝对定位 input层级比view高
 		
 		input 绑定 focus 事件 当聚焦输入时设置opacity为1 
	 		绑定 blur 事件 当失焦时设置opacity为0  (设置透明度是为了下次点击 时 聚焦事件可以触发)

	 	失焦后opacity 为0 input组件看不到 时 view元素显示出来 不会飘在其他元素上
	
	
 		
 	-->




<template>
	<view class="">
		<view class="" style="height: 100vh;"></view>
		<view class="line">
			<view class="wrap">
				<input
					:style="{ opacity: flag ? 1 : 0 }"
					type="text"
					class="input-style input-dom"
					v-model="str"
					@focus="focusFn"
					@blur="blurFn"
				/>
				<view :style="{ opacity: flag ? 0 : 1 }" class="input-style view-dom">{{ str }}</view>
			</view>
		</view>
		<view
			style="width: 100vw; height: 400rpx; background: green; position: fixed; bottom: 0; left: 0; z-index: 100;"
		></view>

		<view style="height: 400rpx;"></view>
	</view>
</template>

<script>
export default {
	beforeCreate() {},
	data() {
		return {
			str: '',
			flag: false
		};
	},
	methods: {
		focusFn() {
			this.flag = true;
			console.log('focusFn');
		},
		blurFn() {
			this.flag = false;
			console.log('blurFn');
		}
	},
	onLoad() {}
};
</script>

<style scoped lang="scss">
.line {
	background: red;
	width: 80vw;
	height: 300rpx;

	.wrap {
		position: relative;
		width: 300rpx;
		height: 60rpx;

		.input-style {
			position: absolute;
			border: 1px solid green;
			width: 300rpx;
			height: 60rpx;
			background: #cccccc;
			text-align: right;

			&.view-dom {
				z-index: 1;
				text-overflow: ellipsis;
				white-space: nowrap;
				overflow: hidden;
			}
			&.input-dom {
				z-index: 2;
			}
		}
	}
}
</style>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值