【发布时间】:2022-01-06 06:02:21
【问题描述】:
总结
我有一张图片(1920 像素 x 1080 像素),我想将其拆分为 40 像素 x 40 像素的小图片。我想在网页上显示图像,使其看起来像原始的完整 1920x1080 图像。它将是 48 个图像宽(列)乘 27 行。
对于每张图片,我希望能够拥有不同的超链接和替代文本。
当屏幕尺寸发生反应性改变时,我希望图像也按比例缩小,这样它们就不会环绕页面,或者滚出页面。
框架
目前正在使用 Vue 和 Vuetify。
试过
-
我尝试过使用完整图像而不将其拆分并在其上放置图像映射。这在全屏时完美运行,但是,当页面响应调整以调整大小时,图像映射坐标会随着基础图像大小的变化而中断。我不知道如何获得图像的比例来相应地调整图像映射。
<template v-slot:activator="{ on, attrs }"> <v-img ref="imageShow" usemap="" class="image" contain src="@/assets/sections/fullsize_image.jpg" v-resize="onResize"> <!-- Loop over array of plots by row & col to generate this. Eg. top: = rowId * 40... left: = colPos * 40 --> <span v-for="(i, row) in listSections" :key="row" justify="center" align="center" class="d-flex flex-nowrap" > <!-- i contains an object with URL, alt text etc in it --> <span v-for="col in Object.keys(i)" :key="col" > <a v-bind="attrs" v-on="on" @click="info = i[col]" :style="`${ returnStyle(row,col) }`"></a> </span> </span> </v-img> </template>
returnStyle 是一个计算函数,用于计算图片各部分的图像映射。如果由于反应图像调整大小而调整了图像,我不确定如何在计算函数中考虑这一点:
computed: {
returnStyle: function() {
return function(row, col) {
return "position:absolute; top: " + (row * 40) + "px; left: " + (col * 40) + "px; height:40px; width: 40px;"
}
}
}
-
我已经尝试使用 Vuetify v-row's 和 v-col's 来包含 v-img...图像没有正确缩小,或者它们正在换行或只是滚动页面 (class="d-flex flex-nowrap")。
<v-container pa-0 fluid ma-0> <v-row no-gutters style="maxWidth: 1920px; width: 100%;" class="d-flex flex-nowrap"> <v-col> <v-img :src="require(`../assets/section/section_0_0.jpg`)"></v-img> </v-col> <!-- ... 46 more v-col/v-img's --> </v-row> <v-row no-gutters style="maxWidth: 1920px; width: 100%;" class="d-flex flex-nowrap"> <v-col> <v-img :src="require(`../assets/section/section_2_0.jpg`)"></v-img> </v-col> <!-- ... 46 more v-col/v-img's --> </v-row> <v-row no-gutters style="maxWidth: 1920px; width: 100%;" class="d-flex flex-nowrap"> <v-col> <v-img :src="require(`../assets/section/section_2_0.jpg`)"></v-img> </v-col> <!-- ... 46 more v-col/v-img's --> </v-row> </v-container>
我曾建议为此考虑使用 Flex 或 CSS Grid,但是,我有点担心我会结束对它们的试验并最终遇到同样的问题。
非常感谢任何建议。谢谢。
【问题讨论】:
-
拥有这么多图像我听起来有点噩梦 - 并确保无论视口尺寸如何,它们都会绝对准确地相互对接(没有分割像素)。当你说你想要一个不同的替代文本时,你真的希望屏幕阅读器能正确读出吗?就点击将用户带到正确位置的href而言?
标签: css vue.js flexbox vuetify.js