gpt4 book ai didi

css - 重新映射 html 图像链接 + 适合屏幕 + 最大高度和宽度

转载 作者:行者123 更新时间:2023-11-28 08:48:43 25 4
gpt4 key购买 nike

好吧,抱歉各位,这个标题太大了。但大部分标题都解释了我需要什么。

我有一个 HTML 页面,可以在屏幕上显示图像。基本上它是全屏的(在非常宽的屏幕上是个大问题),我正在使用:https://github.com/davidjbradshaw/imagemap-resizer调整我创建的 map 的大小。

这是我的 HTML 代码:

    <body>

<img id="imgg" src="imgs/SampleImage.png" height="100%" width="100%" style="max-height:1414px; max-width:1414px;" alt="Page" usemap="#image_map" border="0">

<map name="image_map" id="image_map">
<area shape="poly" coords=" 104,693, 250,702, 219,1203, 105,1208, 105,692" href="http://wordpress.com" alt="Blog"/>

<area shape="poly" coords=" 376,879, 521,880, 522,1035, 375,1037, 375,880" href="https://www.facebook.com/" alt="Facebook Page"/>
<area shape="poly" coords=" 558,882, 705,883, 705,1036, 563,1036, 559,885" href="https://www.facebook.com/" alt="Facebook Page"/>

<area shape="poly" coords=" 364,1045, 716,1047, 710,1082, 370,1085, 367,1044" href="https://twitter.com/" alt="Twitter Page"/>

<area shape="poly" coords=" 294,1036, 344,1055, 361,1035, 368,917, 370,901, 310,916, 297,945, 292,978, 290,1037, 301,1037" href="https://www.pinterest.com/" alt="Pinterest"/>

<area shape="poly" coords=" 529,898, 555,898, 551,1017, 536,1021, 531,901" href="https://www.pinterest.com/" alt="Pinterest"/>

<area shape="poly" coords=" 718,1033, 715,904, 771,922, 789,1037, 744,1050, 722,1033" href="https://www.pinterest.com/" alt="Pinterest"/>
</map>

</body>

<!--[if lte IE 8]>
<script type="text/javascript" src="js/ie8.polyfil.js"></script>
<![endif]-->

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript" src="js/imageMapResizer.min.js"></script>
<script type="text/javascript">

$('map').imageMapResize();

</script>

我只想让图片显示在页面上,但在一定高度(图片的最大高度和最大宽度)之后,它不应再允许图片被拉伸(stretch),而是显示背景色。

我还在我的 img 标签的“样式”部分尝试使用最大高度和最大宽度属性。不工作。 height="100%"和 width="100%"是为了确保图像看起来不会太大,这是一张 1000x1000 图片,所以在较小的设备上它们必须滚动,这就是我使用它的原因.谢谢大家的帮助!

最佳答案

好吧,看来没人能帮忙了。但我自己想通了!

所以我就把秘诀分享给大家。基本上这不是真正的 secret ,我使用了一个肮脏的小 javascript 技巧而不是 html/css 技巧。它将查看图像高度,检查高度是否小于宽度或宽度是否小于高度并将其中一个设置为较小的高度。例如:高度 = 1000 像素宽度 = 800px

现在 JavaScript 代码将检查哪个较小,然后将高度/宽度设置为较小的尺寸(请记住这是一张方形图像):高度 = 800 像素宽度 = 800px

代码如下:

    <script>
var img = document.getElementById('imgg');
var width = img.clientWidth;
var height = img.clientHeight;

if (width < height) {
img.style.height=width;
}

if (height < width) {
img.style.width=height;
}

</script>

关于css - 重新映射 html 图像链接 + 适合屏幕 + 最大高度和宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27465214/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com