display: flex与position:absolute,IOS个别机型样式不兼容

当小程序页面中的父元素使用display:flex布局时,若其子元素采用position:absolute布局,在苹果6s/6P/6sP设备上会出现兼容性问题,导致页面布局混乱。此问题在开发工具中无法复现,仅在特定真实设备上出现。

在小程序页面中父元素使用display:flex时,子元素使用position:absolute后。在苹果6s/6P/6sP的系统下会出现兼容问题,子元素position:absolute不生效页面出现布局混乱。所以当子元素要用position:absolute,父元素不能使用 display: flex布局。否则会出现兼容问题(开发工具测不出问题,真机会在6s/6P/6sP才能测出问题)

<template> <!-- <view class="modal-overlay" @tap.stop="hideModal" v-if="visible" @touchmove.stop.prevent> --> <view class="modal-overlay" @tap.stop="hideModal" @touchmove.stop.prevent> <view class="modal-content"> <swiper class="swiper" :class="advData.value.length==1?'on':''" :autoplay="autoplay" :duration="duration" @change="stopChange" v-if="advData.type == 'pic' && advData.value.length"> <swiper-item v-for="(item,index) in advData.value" :key="index" @click="jump(item.link)"> <!-- <view class="swiper-item"> --> <view class="swiper-item-img"> <image :src="item.img" mode="aspectFit"></image> </view> <!-- </view> --> </swiper-item> </swiper> <text class="iconfont icon-ic_close1 fs-40 text--w111-fff"></text> </view> </view> </template> <style scoped> .modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background-color: rgba(0, 0, 0, 0.6); display: flex; height: 100%; justify-content: center; align-items: center; z-index: 1000; -webkit-overflow-scrolling: touch; /* 禁用 iOS 弹性滚动 */ } .modal-content { background-size: contain; background-repeat: no-repeat; position: fixed; top: 45%; left: 50%; transform: translate(-50%, -50%); height: 50%; z-index: 1001; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; } .modal-content-mobile { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); height: 30%; background-size: cover; background-position: center; z-index: 1001; } .modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10rpx; } .modal-footer1 { position: relative; top: 32%; transform: translate(-50%, -50%); margin-left: 48%; align-items: center; } .modal-footer2 { position: relative; top: 28%; margin-left: 50%; transform: translate(-50%, -50%); align-items: center; } .modal-footer3 { position: relative; top: 55%; margin-left: 50%; transform: translate(-50%, -50%); align-items: center; } .modal-body { font-size: 25rpx; position: relative; margin: 0 auto; top: 19%; width: 75%; align-items: center; } .modal-body-mobile { font-size: 35rpx; position: relative; margin: 0 auto; top: 35%; width: 80%; align-items: center; } .modal-body view { margin-top: 5%; justify-content: center; align-items: center; } .modal-body-mobile view { margin-top: 5%; justify-content: center; align-items: center; } input { justify-content: center; margin-top: 3%; width: 80%; background: #FFFFFF; border-radius: 8px 8px 8px 8px; padding: 14rpx 32rpx; font-size: 30rpx; } .swiper-item { height: 100%; text-align: center; position: relative; display: flex; align-items: flex-end; flex-direction: column-reverse } .jump-over { position: absolute; height: 325rpx; text-align: center; padding: 0 15rpx; font-weight: bold; z-index: 999; bottom: 20rpx; top: 50%; left: 50%; transform: translate(-50%, -50%); } .jump_img { position: absolute; bottom: 80rpx; left: 50%; transform: translateX(-50%); z-index: 1002; } .swiper-item { height: 100%; text-align: center; position: relative; display: flex; align-items: flex-end; flex-direction: column-reverse } .swiper-item-img { width: 60%; max-width: 800px; margin: 0 auto; height: 100%; position: relative; width: 100%; height: 100%; display: flex; justify-content: center; align-items: center; } .swiper-item-img image { width: 100%; height: 100%; object-fit: contain; } .modal-content { /* position: relative; */ width: 50vw; /* height: 60vh; */ /* max-width: 800px; */ /* display: flex; */ /* flex-direction: column; */ /* align-items: center; */ /* justify-content: center; */ } .swiper { width: 100%; height: 100%; } .icon-ic_close1 { position: absolute; z-index: 1002; } </style> 修改代码:要求:这是一个uniapp的开屏弹窗 根据代码写出来css样式,关闭按钮要放在图片的下方并和图片保持间隔
06-14
类型“PlusWebviewWebviewObject”上不存在属性“capture”。 怎么修改 <template> <view class="webview-container"> <cover-view class="webview-wrapper"> <web-view :src="webviewPath" id="targetWebview" ></web-view> </cover-view> <cover-view class="bottom-action-area"> <cover-view class="capture-btn" @click="generatePdfFromWebview"> <cover-view class="btn-text">生成PDF</cover-view> </cover-view> </cover-view> </view> </template> <script setup lang="ts"> import { onLoad } from '@dcloudio/uni-app'; import { ref } from 'vue'; const webviewPath = ref(''); onLoad((options: any) => { if (options.url) { webviewPath.value = decodeURIComponent(options.url); } }); const generatePdfPreview = () => { // 获取当前webview对象 const pages = getCurrentPages(); const currentPage = pages[pages.length - 1]; const webview = currentPage.$getAppWebview(); // 捕获网页内容并转换为PDF webview.capture((captureResult) => { if (captureResult) { // 生成PDF文件路径 const pdfPath = '_doc/' + Date.now() + '.pdf'; // 将网页截图保存为PDF plus.io.resolveLocalFileSystemURL(pdfPath, (entry) => { entry.createWriter((writer) => { writer.write(captureResult); writer.onwriteend = () => { // 跳转到PDF预览页 if (uni.getSystemInfoSync().platform === 'android') { // 安卓使用Intent唤起系统PDF查看器 plus.runtime.openFile(pdfPath); } else { // iOS使用PDF.js预览 uni.navigateTo({ url: `pages/home/components/Webpreview?pdfPath=${encodeURIComponent(pdfPath)}` }); } }; }); }); } }, { format: 'pdf', // 指定生成PDF格式 quality: 100, // 质量设置 filename: 'webview-content' // 文件名 }); }; </script> <style> .webview-container { position: relative; width: 100%; height: 100vh; overflow: hidden; } .webview-wrapper { height: calc(100vh - 120rpx); width: 100%; overflow: hidden; } .bottom-action-area { position: fixed; bottom: 0; left: 0; right: 0; z-index: 100; background-color: #007aff; padding: 30rpx; padding-bottom: constant(safe-area-inset-bottom); padding-bottom: env(safe-area-inset-bottom); display: flex; justify-content: center; align-items: center; } .capture-btn { width: 100%; height: 90rpx; background-color: #007aff; border-radius: 45rpx; box-shadow: 0 4rpx 10rpx rgba(0, 0, 0, 0.2); display: flex; align-items: center; justify-content: center; } .btn-text { color: #ffffff; font-size: 32rpx; font-weight: 500; } /* PDF预览组件样式 */ .custom-preview { position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 9999; background-color: rgba(0, 0, 0, 0.9); display: flex; flex-direction: column; align-items: center; padding: 0 0 40rpx 0; box-sizing: border-box; } .preview-header { width: 100%; height: 100rpx; background-color: #007aff; color: #ffffff; display: flex; align-items: center; justify-content: center; position: relative; } .title-container { display: flex; align-items: center; justify-content: center; width: 100%; } .preview-title { color: #ffffff; font-size: 34rpx; font-weight: bold; } .close-btn { position: absolute; right: 30rpx; font-size: 40rpx; color: white; } .preview-pdf { width: 100%; height: calc(100% - 100rpx - 120rpx); background-color: white; } .action-buttons { display: flex; width: 100%; justify-content: space-between; padding: 30rpx 5%; margin-top: auto; background-color: #353336; box-sizing: border-box; } .action-btn { flex: 1; height: 90rpx; border-radius: 12rpx; display: flex; align-items: center; justify-content: center; margin: 0 15rpx; color: #ffffff; font-size: 34rpx; font-weight: 500; } .cancel-btn { background-color: #666; } .confirm-btn { background-color: #007aff; } </style>
08-09
<!-- 主要内容区域 --> <view class="main-content flex flex-between"> <view class="area-item" v-for="area in areaList" :key="area.areaId" v-if="area.areaId==mapId"> <!-- 区域图片 --> <image :src="area.image" class="area-img" mode="widthFix"></image> </view> <view class="description-card"> <web-view :src="mapUrl" @message="handleMessage" ref="webviewRef" debug></web-view> </view> <!-- 功能导航 --> <view class="feature-nav" style="z-index: 99999;"> <view class="feature-item" v-for="(item, index) in features" :key="index" @click="navigateToFeature(item.path)"> <text class="feature-title">{{item.title}}</text> </view> </view> </view>/* 主要内容区域 */ .main-content { padding: 40rpx 80rpx; margin-top: 20rpx; gap: 20rpx; display: flex; position: relative; } .area-item { width: 156rpx; height: 238rpx; position: absolute; left: 5%; top: 8%; z-index: 9999; } .area-img { width: 100%; height: 100%; } /* .description-card { width: 80%; height: 420px; border-radius: 25px; position: relative; border: 8px solid; border-image: linear-gradient(180deg, #E3383B 0%, #E3393B 1%, #F47C58 100%) 8; } */ .description-card { width: 70%; height: 600px; position: relative; z-index: 0; overflow: hidden; } /* 创建渐变边框 */ .description-card::before { content: ""; position: absolute; top: 0px; left: 0px; right: 0px; bottom: 0px; background: linear-gradient(180deg, #E3383B 0%, #F47C58 100%); border-radius: 60rpx; z-index: -1; } /* 功能导航 */ .feature-nav { flex: 1; min-width: 180rpx; display: flex; align-items: center; flex-direction: column; justify-content: space-around; margin-left: 20rpx; } .feature-item { font-family: 'ShuHuiTi'; width: 80%; text-align: center; line-height: 120rpx; cursor: pointer; background-image: url('/static/images/border.png'); background-position: center; background-repeat: no-repeat; background-size: 100% 100%; } .feature-title { display: block; font-size: 70rpx; font-weight: bold; color: #FF4444; } 为什么在浏览器查看h5正常,在模拟器查看app只有地图
最新发布
08-19
<template> <view class="webview-container"> <cover-view class="webview-wrapper"> <web-view :src="webviewPath" id="targetWebview" ></web-view> </cover-view> <cover-view class="bottom-action-area"> <cover-view class="capture-btn" @click="generatePdfFromWebview"> <cover-view class="btn-text">生成PDF</cover-view> </cover-view> </cover-view> </view> </template> <script setup lang="ts"> import { onLoad} from '@dcloudio/uni-app'; import { ref } from 'vue'; import jsPDF from 'jspdf'; declare const plus: any; const webviewPath = ref(''); // const ws = ref<any>(null); // const pdfFilePath = ref(''); const showPdfPreview = ref(false); const platform = ref(''); // const htmlContent = ref(''); const pdfViewerUrl = ref(''); onLoad((options: any) => { if (options.url) { webviewPath.value = decodeURIComponent(options.url); pdfViewerUrl.value = `/static/pdfjs/web/viewer.html?file=${encodeURIComponent(webviewPath.value)}`; } // 获取当前平台 const systemInfo = uni.getSystemInfoSync(); platform.value = systemInfo.platform; }); const generatePdfFromWebview = async () => { const pdfUrl = 'https://example.com/document.pdf'; uni.navigateTo({ url: `/pages/pdf-preview?pdfUrl=${encodeURIComponent(pdfUrl)}` }); } </script> <style> .webview-container { position: relative; width: 100%; height: 100vh; overflow: hidden; } .webview-wrapper { height: calc(100vh - 120rpx); width: 100%; overflow: hidden; } .bottom-action-area { position: fixed; bottom: 0; left: 0; right: 0; z-index: 100; background-color: #007aff; padding: 30rpx; padding-bottom: constant(safe-area-inset-bottom); padding-bottom: env(safe-area-inset-bottom); display: flex; justify-content: center; align-items: center; } .capture-btn { width: 100%; height: 90rpx; background-color: #007aff; border-radius: 45rpx; box-shadow: 0 4rpx 10rpx rgba(0, 0, 0, 0.2); display: flex; align-items: center; justify-content: center; } .btn-text { color: #ffffff; font-size: 32rpx; font-weight: 500; } /* PDF预览组件样式 */ .custom-preview { position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 9999; background-color: rgba(0, 0, 0, 0.9); display: flex; flex-direction: column; align-items: center; padding: 0 0 40rpx 0; box-sizing: border-box; } .preview-header { width: 100%; height: 100rpx; background-color: #007aff; color: #ffffff; display: flex; align-items: center; justify-content: center; position: relative; } .title-container { display: flex; align-items: center; justify-content: center; width: 100%; } .preview-title { color: #ffffff; font-size: 34rpx; font-weight: bold; } .close-btn { position: absolute; right: 30rpx; font-size: 40rpx; color: white; } .preview-pdf { width: 100%; height: calc(100% - 100rpx - 120rpx); background-color: white; } .action-buttons { display: flex; width: 100%; justify-content: space-between; padding: 30rpx 5%; margin-top: auto; background-color: #353336; box-sizing: border-box; } .action-btn { flex: 1; height: 90rpx; border-radius: 12rpx; display: flex; align-items: center; justify-content: center; margin: 0 15rpx; color: #ffffff; font-size: 34rpx; font-weight: 500; } .cancel-btn { background-color: #666; } .confirm-btn { background-color: #007aff; } </style> 这是webview页面 应该怎样修改
08-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值