gpt4 book ai didi

javascript - 如何在网页上找到合适的位置进行点击?

转载 作者:搜寻专家 更新时间:2023-10-31 22:36:42 24 4
gpt4 key购买 nike

麻烦很大,但任务很简单。

我有一张背景图片,上面有小花。当用户按下它时,我需要执行一些操作。然而,根据屏幕的分辨率,花被放置在屏幕的不同区域。

如何将“小花”与 a:href 的悬停区域连接起来?

  <style>
body {
background-image: url(images/bg.jpg);
}
</style>

<body>
<div>
<h1><a href=#>press it where small flower is situated on an page</a></h1>
</div>
</body>

让我举个例子。因此,当按下橙色花朵时我需要不同的网络链接,或者白色花朵的蓝色和第三个不同的网络链接等等。如果它是一个屏幕,我只是将它划分为一些虚拟方 block ,但对于许多不同的分辨率,这样做绝对是垃圾:https://gessoemsp.org/wp-content/uploads/2013/08/lovely-small-flower-garden-plans.jpg

最佳答案

使用 map

步骤01

制作一张 map

使用Free Online Image Map Generator

enter image description here

步骤02

设置网址

enter image description here

步骤03

生成代码

<!-- Image Map Generated by http://www.image-map.net/ -->
<img src="l35x9.jpg" usemap="#image-map">

<map name="image-map">
<area target="_blank" alt="Yelow flower" title="Yelow flower" href="https://www.google.com/q=yelow+flower" coords="39,686,204,502" shape="rect">
<area target="_blank" alt="Yelow flower" title="Yelow flower" href="https://www.google.com/q=yelow+flower" coords="981,533,789,390" shape="rect">
<area target="_blank" alt="Pink+flower" title="Pink+flower" href="https://www.google.com/q=Pink+flower" coords="517,318,781,556" shape="rect">
<area target="_blank" alt="light pink flower" title="light pink flower" href="https://www.google.com/q=light+pink+flower" coords="449,438,21,278" shape="rect">
</map>

第 04 步:图像映射演示 - 非响应

Live demo 1 - View

Live demo 1 - Code - click preview after you open

enter image description here

enter image description here

<!DOCTYPE html>
<html>
<head>
<title>HTML area Tag</title>
</head>

<!-- Image Map Generated by http://www.image-map.net/ -->
<img src="/image/l35x9.jpg" usemap="#image-map">
<map name="image-map">
<area target="_blank" alt="Yelow flower" title="Yelow flower" href="https://www.google.com?q=yelow+flower" coords="39,686,204,502" shape="rect">
<area target="_blank" alt="Yelow flower" title="Yelow flower" href="https://www.google.com?q=yelow+flower" coords="981,533,789,390" shape="rect">
<area target="_blank" alt="Pink+flower" title="Pink+flower" href="https://www.google.com?q=Pink+flower" coords="517,318,781,556" shape="rect">
<area target="_blank" alt="light pink flower" title="light pink flower" href="https://www.google.com?q=light+pink+flower" coords="449,438,21,278" shape="rect">
</map>
</body>
</html>

第 05 步图像映射演示 - 响应式

Live demo 2 - View

Live demo 2 - Code - click preview after you open

二手 imageMapResizer + jquery + bootstrap

enter image description here

<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

<title>Hello, world!</title>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-sm">
One of three columns
</div>
<div class="col-sm">
One of three columns
</div>
<div class="col-sm">
<!-- Image Map Generated by http://www.image-map.net/ -->
<img src="/image/l35x9.jpg" usemap="#image-map1" class="img-fluid" >

</div>
</div>
<div class="row">
<div class="col-sm">
One of three columns
</div>
<div class="col-sm">
<!-- Image Map Generated by http://www.image-map.net/ -->
<img src="/image/l35x9.jpg" usemap="#image-map2" class="img-fluid" >

</div>
</div>

<div class="row">
<div class="col-sm">
<!-- Image Map Generated by http://www.image-map.net/ -->
<img src="/image/l35x9.jpg" usemap="#image-map3" class="img-fluid" >
</div>
</div>
</div>

<map name="image-map1">
<area target="_blank" alt="Yelow flower" title="Yelow flower" href="https://www.google.com?q=yelow+flower" coords="39,686,204,502" shape="rect">
<area target="_blank" alt="Yelow flower" title="Yelow flower" href="https://www.google.com?q=yelow+flower" coords="981,533,789,390" shape="rect">
<area target="_blank" alt="Pink+flower" title="Pink+flower" href="https://www.google.com?q=Pink+flower" coords="517,318,781,556" shape="rect">
<area target="_blank" alt="light pink flower" title="light pink flower" href="https://www.google.com?q=light+pink+flower" coords="449,438,21,278" shape="rect">
</map>
<map name="image-map2">
<area target="_blank" alt="Yelow flower" title="Yelow flower" href="https://www.google.com?q=yelow+flower" coords="39,686,204,502" shape="rect">
<area target="_blank" alt="Yelow flower" title="Yelow flower" href="https://www.google.com?q=yelow+flower" coords="981,533,789,390" shape="rect">
<area target="_blank" alt="Pink+flower" title="Pink+flower" href="https://www.google.com?q=Pink+flower" coords="517,318,781,556" shape="rect">
<area target="_blank" alt="light pink flower" title="light pink flower" href="https://www.google.com?q=light+pink+flower" coords="449,438,21,278" shape="rect">
</map>
<map name="image-map3">
<area target="_blank" alt="Yelow flower" title="Yelow flower" href="https://www.google.com?q=yelow+flower" coords="39,686,204,502" shape="rect">
<area target="_blank" alt="Yelow flower" title="Yelow flower" href="https://www.google.com?q=yelow+flower" coords="981,533,789,390" shape="rect">
<area target="_blank" alt="Pink+flower" title="Pink+flower" href="https://www.google.com?q=Pink+flower" coords="517,318,781,556" shape="rect">
<area target="_blank" alt="light pink flower" title="light pink flower" href="https://www.google.com?q=light+pink+flower" coords="449,438,21,278" shape="rect">
</map>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<script src="https://rawgit.com/davidjbradshaw/imagemap-resizer/master/js/imageMapResizer.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('map').imageMapResize();
});
</script>
</body>
</html>




</body>
</html>

更多 map

HTML img usemap Attribute

html - Responsive image map - Stack Overflow

stowball/jQuery-rwdImageMaps: Responsive Image Maps jQuery Plugin

Responsive Image Maps jQuery Plugin

davidjbradshaw/image-map-resizer: Responsive HTML Image Maps

html - How using usemap in div background url - Stack Overflow

How to create clickable areas in an image in HTML

关于javascript - 如何在网页上找到合适的位置进行点击?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54057726/

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