object-fit:cover 的ie 兼容写法

本文探讨了object-fit属性在IE浏览器中的兼容性问题,并提供了一种使用绝对定位和transform来实现类似效果的替代方案。

object-fit在ie浏览器中是不兼容的,在网络上搜索了一下这方面的内容,发现看不懂,完全看不懂好吗!大大的眼睛大大的疑惑
在这里插入图片描述
表示好难过!
不说了上代码

.fu{
		width: 100%;
		height: 100%;
		.fu1{
			position:relative;
		    img{
		        min-width: 100%;
		        min-height: 100%;
				object-fit:cover ;
				position: absolute;
				left: 50%;
				transform: translate3d(-50%,0,0);
				z-index: -1;
				top: 0;
		    }
		}
	}

如果有用,请好评呦

<div class="carousel"> <div class="carousel-list" :style="{ transform: 'translateX(' + (-i_index * 100) + '%)' }"> <div v-for="(img, index) in images" :key="index"> <img :src="img.src" :alt="img.alt"> </div> </div> <button class="carousel-btn prev" @click="prev">左</button> <button class="carousel-btn next" @click="next">右</button> <div class="indicators"> <span v-for="(img, index) in images" :key="index" :class="{ 'indicator': true, 'active': index === i_index }" @click="goTo(index)" ></span> </div> </div>/*全局定义*/ *, *::before, *::after { box-sizing: border-box; } /*全局定义*/ /*整个body*/ html,body{ margin: 0; padding: 0; height: 100%; width: 100%; background-color: #e6f7ff; } /*整个body*/ /*导航栏的定义*/ #n_nav{ width: 100%; height: 100%; border: 1px solid red; } nav{ width: 100%; height: 7%; display: flex; border: 1px solid red; background: linear-gradient(to bottom, #1e90ff, #87ceeb); gap: 10px; } .nav_router-link{ display: flex; width: 25%; height: 100%; font-size: 40px; border: 1px solid blueviolet; text-align: center; justify-content: center; align-items: center; text-decoration: none; font-family: 楷体,sans-serif; color: white; letter-spacing: 5px; } /*导航栏的定义*/ .carousel { width: 100%; height: 80%; display: flex; margin-top: 5%; margin-left: 5%; position: relative; overflow: hidden; border-radius: 8px; border: 2px solid rebeccapurple; } .carousel-list { display: flex; width: 100%; height: 100%; transition: transform 0.5s ease; } .carousel-list > div { min-width: 100%; height: 100%; } .carousel-list img { width: 100%; height: 100%; object-fit: cover; } .carousel-btn { position: absolute; top: 50%; transform: translateY(-50%); background-color: rgba(0,0,0,0.5); color: white; border: none; padding: 10px 15px; cursor: pointer; font-size: 16px; z-index: 10; } .prev { left: 10px; } .next { right: 10px; } .indicators { position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); display: flex; gap: 8px; } .indicator { width: 12px; height: 12px; background-color: #ccc; border-radius: 50%; cursor: pointer; } .indicator.active { background-color: white; }为什么会超出,怎么设置
11-02
<script setup lang="ts"> import {getListTable} from "@/api/modules/inedx"; import {useFileType} from "@/utils/filesType"; definePage({ name: 'home', layout: "tabbar", style: { navigationBarTitleText: '推荐', navigationStyle: 'custom', disableScroll: true }, }) const {getFileType} = useFileType() const classifyList = ref<any>([]) // 获取分类数据 const getClassifyList = async () => { useGlobalLoading().loading('加载中...') const res = await getListTable().finally(() => { useGlobalLoading().close() }); classifyList.value = res.data console.log(classifyList.value) useGlobalLoading().close() } const chunkFiles = (arr, size) => { if (!arr || !Array.isArray(arr)) return []; const chunks = []; for (let i = 0; i < arr.length; i += size) { chunks.push(arr.slice(i, i + size)); } return chunks; } onMounted(() => { getClassifyList() }) </script> <template> <view class="index-page-container"> <wd-navbar fixed custom-style="background-color: transparent !important; height: 100rpx !important;" safeAreaInsetTop> <template #left> <view class="title-box pl4"> <text class="title-text"></text> </view> </template> </wd-navbar> <view class="container"> <scroll-view :scroll-y="true" class="list-box"> <view class="top-box"> <view class="top"> <view class="top-icon-box"> <wd-icon name="add" size="18px"></wd-icon> </view> <text class="top-text">AI修图</text> </view> </view> <view class="video" v-for="item in classifyList" :key="item?.id" v-show="item.files.length > 0"> <wd-card custom-class="list-item"> <template #title> <view class="list-text" @click="useGlobalToast().success(item.name)"> <text class="text-title">{{ item?.name }}</text> <view class="title-tip"> <wd-icon name="arrow-right" size="22px"></wd-icon> </view> </view> </template> <scroll-view :scroll-x="true" :show-scrollbar="false" class="files-package-scroll"> <view class="files-box"> <!-- 大号 --> <view v-if="item.style == '1'" v-for="(file, index) in item?.files" :key="index + '-1'" class="files-item-large"> <image v-if="'image' == getFileType(file.ossUrl)" :src="file?.ossUrl" mode="scaleToFill" class="list-image-large"/> <video v-else :src="file?.ossUrl" :controls="false" :autoplay="true" :loop="true" object-fit="fill" :show-bottom-progress="false" class="list-video-large" muted/> </view> <!-- 格子 --> <view v-else-if="item.style == '2'" v-for="(file, index) in item?.files" :key="index + '-2'" class="files-item-cell"> <view v-for="(group, groupIndex) in chunkFiles(item?.files, 5)" :key="groupIndex" class="card-horizontal-group"> <!-- 左侧大项 --> <view v-if="group[0]" class="left-large-item"> <image v-if="getFileType(group[0].ossUrl) === 'image'" :src="group[0].ossUrl" mode="scaleToFill" class="list-image-left-large"/> <video v-else :src="group[0].ossUrl" :controls="false" :autoplay="true" :loop="true" object-fit="fill" :show-bottom-progress="false" class="list-video-left-large" :muted="true"/> </view> <!-- 右侧四个小项:改为 上2下2 的 2x2 网格 --> <view class="right-grid-2x2"> <view v-for="(subFile, subIdx) in group.slice(1, 5)" :key="subIdx" class="right-grid-item"> <image v-if="getFileType(subFile.ossUrl) === 'image'" :src="subFile.ossUrl" mode="aspectFill" class="list-image-right-small"/> <video v-else :src="subFile.ossUrl" :controls="false" :autoplay="true" :loop="true" object-fit="cover" :show-bottom-progress="false" class="list-video-right-small" :muted="true"/> </view> </view> </view> </view> <!-- 默认样式(小号) --> <view v-else v-for="(file, index) in item?.files" :key="index" class="files-item"> <image v-if="'image' == getFileType(file.ossUrl)" :src="file?.ossUrl" mode="scaleToFill" class="list-image"/> <video v-else :src="file?.ossUrl" :controls="false" :autoplay="true" :loop="true" object-fit="fill" :show-bottom-progress="false" class="list-video" muted/> </view> </view> </scroll-view> </wd-card> </view> </scroll-view> <!-- 底部占位,防止内容被 tabbar 遮挡 --> <!-- <view class="safe-area-placeholder"></view> --> </view> </view> </template> <style scoped lang="scss"> .index-page-container { height: 100vh; /* 确保根容器占满视口 */ display: flex; flex-direction: column; overflow: hidden; } .container { display: flex; flex: 1; padding-top: calc(100rpx + 54px); box-sizing: border-box; flex-direction: column; margin-bottom: 190rpx; } .top-box { height: 180rpx; width: 100%; display: inline-flex; align-items: center; justify-content: center; margin: 10rpx 0 20rpx 0; } .top { height: 100%; width: 93%; border-radius: 20rpx; border: rgba(89, 225, 255, 0.77) solid 2rpx; display: flex; flex-direction: column; align-items: center; justify-content: center; } .top-icon-box { height: 80rpx; width: 80rpx; border-radius: 30%; display: flex; align-items: center; justify-content: center; margin-bottom: 10rpx; background-color: rgba(181, 89, 255, 0.53); } .top-text { font-weight: 500; } .list-box { width: 100%; margin-top: 30rpx; /* 占据剩余空间,使 scroll-view 内部可滚动 */ flex: 1; /* 防止溢出 */ height: 0; overflow-y: auto; :deep() { .wd-card { margin: 0 !important; } .list-item { background: transparent !important; .wd-card__title-content { padding: 16rpx 0 !important; } } } } .list-text { display: flex; flex-direction: row; justify-content: space-between; align-items: center; } .text-title { font-size: 32rpx; font-weight: 600; } /* 占位元素:匹配 tabbar 高度 */ .safe-area-placeholder { height: 180rpx; /* 根据你的 tabbar 实际高度调整 */ } /* 如果是 iPhoneX 等有底部安全区的设备,也可以额外兼容 */ /* 使用 env(safe-area-inset-bottom) 更智能 */ .safe-area-placeholder::after { content: ''; display: block; height: env(safe-area-inset-bottom, 0px); /* 安全区延伸 */ background-color: transparent; } .files-package-scroll { white-space: nowrap; /* 关键:防止子项换行 */ width: 100%; } .files-box { display: inline-flex; flex-direction: row; height: 100%; width: 100%; } /** 默认 */ .files-item { height: 320rpx; margin-right: 15rpx; } .list-image { height: 100%; width: 220rpx; border-radius: 23rpx; } .list-video { height: 100%; width: 220rpx; border-radius: 23rpx; } /** 大号 */ .files-item-large { height: 420rpx; margin-right: 15rpx; } .list-image-large { height: 100%; width: 300rpx; border-radius: 23rpx; } .list-video-large { height: 100%; width: 300rpx; border-radius: 23rpx; } /** 格子 */ .files-item-cell { height: 520rpx; margin-right: 15rpx; } /* 每个横向卡片:左1右4 的固定宽度容器 */ .card-horizontal-group { display: flex; width: 90vw; /* 控制每个组的宽度,可根据设计调整 */ height: 100%; overflow: hidden; flex-shrink: 0; /* 防止压缩 */ } /* 左侧大图/视频 */ .left-large-item { flex: 2; margin-right: 10rpx; } .list-image-left-large, .list-video-left-large { width: 100%; height: 100%; border-radius: 23rpx; } /* 右侧 2x2 网格:上面两个,下面两个 */ .right-grid-2x2 { flex: 2; display: grid; grid-template-columns: 1fr 1fr; /* 两列等宽 */ grid-template-rows: 1fr 1fr; /* 两行等高 */ gap: 15rpx; /* 单元格间距 */ } /* 每个小格子 */ .right-grid-item { overflow: hidden; border-radius: 23rpx; } .list-image-right-small, .list-video-right-small { width: 100%; height: 100%; object-fit: cover; } </style> 怎么把格子的内容循环显示不是重复显示,不要重复向下循环
最新发布
12-01
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值