RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 1268176
Accepted
Sevastopol'
Sevastopol'
Asked:2022-04-10 00:48:07 +0000 UTC2022-04-10 00:48:07 +0000 UTC 2022-04-10 00:48:07 +0000 UTC

如何绘制地图,在其上放置点(标记)并在悬停时为工具提示(工具提示)设置动画?

  • 772

我有以下地图图像:

地图

任务:我需要使用使之成为可能的手段和技术来绘制这样的地图,并在其上放置点(标记),以指示城市。此外,单击标记时,应出现带有城市名称的弹出提示(工具提示)。

  1. 如果无法使用代码再现(绘制)地图,则允许使用其图像。这可以通过两种方式完成:通过应用属性将其用作背景图像,background或者使用标签将其作为带有图像的文件插入,<img>通过src.

变体background:

div {
  width: 800px;
  height: 506px;
  background: url(https://isstatic.askoverflow.dev/0lfnZ.jpg);
}
<div></div>

使用标签的变体<img>:

<img src="https://isstatic.askoverflow.dev/0lfnZ.jpg">

  1. 有必要通过表示城市的坐标点(标记)在此地图上放置。怎么可能做到这一点?

这是标记代码:

span {
  display: block;
  position: relative;
  margin: 30px auto;
  width: 10px;
  height: 10px;
  background-color: red;
  border-radius: 10px;
  cursor: pointer;
}

span:hover::before {
  content: "";
  position: absolute;
  top: -10px;
  left: -10px;
  width: 30px;
  height: 30px;
  border-radius: 30px;
  background-color: red;
  animation: animate 1.5s infinite normal ease-out;
}

@keyframes animate {
  from {
    transform: scale(0);
    opacity: .5
  }
  to {
    transform: scale(2);
    opacity: 0;
  }
}
<span></span>

以下是城市列表:

<p>Севастополь</p>
<p>Симферополь</p>
<p>Евпатория</p>
<p>Феодосия</p>
<p>Керчь</p>
<p>Ялта</p>

  1. 单击标记时,工具提示应显示城市名称。怎么可能做到这一点?例如,这样的工具提示应该如下所示(它的形状、颜色、大小无关紧要),如下所示:

线索

建议通过任何方式并借助问号中指示的任何技术来解决问题。特别欢迎对您的实现进行详细描述。

javascript
  • 2 2 个回答
  • 10 Views

2 个回答

  • Voted
  1. Best Answer
    Alexandr_TT
    2022-04-12T19:15:07Z2022-04-12T19:15:07Z

    结果应该是这样的:

    jsfiddle

    在此处输入图像描述

    #1 工具提示

    <g>
    <title>Джанкойский район
      Площадь, км. кв.  - 2 666,96      
      Население, чел. - 64 808
    </title>
    </g>
    

    如果您将鼠标悬停在一个对象上,那么一段时间后,系统tooltipSVG 将出现,其中包含在标签之间添加的文本 <title>

    #2。城市标志

    下面是 Dzhankoy 区的代码,其中添加了圆圈和城市名称作为标记

     .state {
        stroke: dodgerblue;
        transform-origin: center center;
     transform-box: fill-box;
     transition:  1s;
      }
     
     text{
     font-size:24px;
     fill:black;
     }
     
     circle{
     fill:gold;
     stroke:red;
     stroke-width:3; 
     }
    <svg xmlns="http://www.w3.org/2000/svg" version="1.1" id="Layer_1" x="0" y="0" xml:space="preserve" viewBox="0 0 1697.6 1072.6">
      <g>
               <title>Джанкойский район
               Площадь, км. кв.  - 2 666,96     
               Население, чел. - 64 808 </title>
              <path class="state" id="Джанкойский район" fill="#FFD6AA" d="M669 176h-2l-1-1v-3-2l-1-4-7-7c-2-2-5-5-5-8v-2l2-2 4-2c3-4 4-8 4-12l-1-12-1-5-3-3-6-3-4-3-1-3 3-8 5 6 20 17 8 8 7 7 1 4c1 3-2 7-2 12l1 6 7 8c2 2 5 4 9 4l2-1 3-2 1-12c0-13-3-27-12-35l-6-4-5-2c-3-2-7-6-10-11 10 3 23 7 30 12 3 2 4 4 5 6 2 3 2 7 2 11 0 5 0 9 2 14l2 5 2 1 3 1 2-1 2-3a37 37 0 001-20l-2-5-1-1 1-2 4-4 4-2 1 4-1 11c0 2 0 5 2 7 2 5 6 7 9 7l10 2h2l2-2 2-16a65 65 0 012-10 4 4 0 011-1l2-1 4 2 7 10 3 6h-1l-3 3-2 4-1 4 1 3c2 2 3 3 5 3l4 1h1a6 6 0 003-1v1l1 2 2 3 8 7-4 3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1v-1l1-2 1-1v-1l1-1 3-5c2-3 4-4 6-5 2-2 5-3 6-6l2-7c-1-6-5-11-5-17l-1-3 1-9c0-3 0-5-2-8l6-3c2-2 5-4 5-7l-1-3-3-3-3-2-1-4-1-6-5-5 1-1c0-5 0-9 2-12s3-7 7-10l10-2c4 0 7 0 11-2l1-2c-3-7-8-15-14-19l-1-1h-1-1l-2-3c-3-4-5-6-5-10v-3l-1-3-2-1z"  />
                     <g transform="translate(-850,-150)">
                         <text x="1580" y="370">Джанкой</text> 
                         <circle cx="1610" cy="400" r="15" />
                    </g> 
                </g> 
    </svg>          

    #3。悬停时缩放区域

    document.querySelectorAll('path.state').forEach(path => {
      path.addEventListener('mouseover', e => {
      path.parentNode.parentNode.append(path.parentNode);
     const paths = [...document.querySelectorAll('path.state')]
     setTimeout(()=> {
     paths[paths.length - 1].classList.add('scaled');    
     },20)
     
      });
    }); 
    document.querySelectorAll('path.state').forEach(path => {
      path.addEventListener('mouseout', e => {
     path.parentNode.parentNode.append(path.parentNode);
     const paths = [...document.querySelectorAll('path.state')]
     
        setTimeout(()=> {
    paths[paths.length - 1].classList.remove('scaled');       
     },20)
      });
    });
    

    document.querySelectorAll('path.state').forEach(path => {
      path.addEventListener('mouseover', e => {
      path.parentNode.parentNode.append(path.parentNode);
     const paths = [...document.querySelectorAll('path.state')]
     setTimeout(()=> {
     paths[paths.length - 1].classList.add('scaled');    
     },20)
     
      });
    }); 
    document.querySelectorAll('path.state').forEach(path => {
      path.addEventListener('mouseout', e => {
     path.parentNode.parentNode.append(path.parentNode);
     const paths = [...document.querySelectorAll('path.state')]
     
        setTimeout(()=> {
    paths[paths.length - 1].classList.remove('scaled');       
     },20)
      });
    });
    .state {
        stroke: dodgerblue;
        transform-origin: center center;
     transform-box: fill-box;
     transition:  1s;
      }
      
      .state.scaled {
     fill:purple;
     stroke:white;
     stroke-width:2px;
       -webkit-transform: scale(1.2);
     transform: scale(1.2);
     }
     text{
     font-size:24px;
     fill:black;
     }
     
     circle{
     fill:gold;
     stroke:red;
     stroke-width:3; 
     }
    <body>
      <section id="map">
    <svg xmlns="http://www.w3.org/2000/svg" version="1.1" id="Layer_1" x="0" y="0" xml:space="preserve" viewBox="0 0 1697.6 1072.6">
      <g>
               <title>Джанкойский район
               Площадь, км. кв.  - 2 666,96     
               Население, чел. - 64 808 </title>
              <path class="state" id="Джанкойский район" fill="#FFD6AA" d="M669 176h-2l-1-1v-3-2l-1-4-7-7c-2-2-5-5-5-8v-2l2-2 4-2c3-4 4-8 4-12l-1-12-1-5-3-3-6-3-4-3-1-3 3-8 5 6 20 17 8 8 7 7 1 4c1 3-2 7-2 12l1 6 7 8c2 2 5 4 9 4l2-1 3-2 1-12c0-13-3-27-12-35l-6-4-5-2c-3-2-7-6-10-11 10 3 23 7 30 12 3 2 4 4 5 6 2 3 2 7 2 11 0 5 0 9 2 14l2 5 2 1 3 1 2-1 2-3a37 37 0 001-20l-2-5-1-1 1-2 4-4 4-2 1 4-1 11c0 2 0 5 2 7 2 5 6 7 9 7l10 2h2l2-2 2-16a65 65 0 012-10 4 4 0 011-1l2-1 4 2 7 10 3 6h-1l-3 3-2 4-1 4 1 3c2 2 3 3 5 3l4 1h1a6 6 0 003-1v1l1 2 2 3 8 7-4 3a76 76 0 01-19 9c-2 0-3 1-3 3v1c0 4 1 9 4 13 4 4 8 6 13 6 7 0 13-3 16-9l4-8 5-2h4v2l-2 6-2 8v1l1 11v3l-1 3-1 5 2 5 4 1 5-2c5-3 11-10 17-17l7-9 4-5 7-2 3-2 1-5v-5c-1-8-5-17-5-25 6 4 13 10 17 16s9 14 9 20v2c-1 4-4 8-7 11l-12 8-8 3c-3 1-5 3-7 6v6l1 1-10 4-8 8-4 5-4 4h-12l-6 1-2 2-1 4v3l2 3a49 49 0 006 7l2 1c3 2 5 2 8 2 6 0 11-2 16-4s10-4 14-4a3 3 0 002-5v-1c9-12 21-25 32-35 6-5 12-7 19-9l1 1c-3 1-6 3-8 6-2 4-3 8-3 13l1 10c0 2 1 3 3 3h2l16-1h9l2 4 2 6 2 2a21 21 0 009 3l-7 9-13 12-5 4-10 8c-3 3-6 7-7 11l1 1c0 2 1 3 3 3 12 0 26-2 37-6 4-1 7-3 9-5l8-5a26 26 0 0113-2l-5 8c-2 4-6 8-6 14l2 3v9l-7 9c-1 3-5 6-6 11l-1 2 2 6a56 56 0 01-14 0c-4 0-7-2-11-3l-4-1c-3 0-5 1-7 3l-2 6 2 8c3 3 7 4 10 4h9c6 1 9 2 13 5l-7 5a40 40 0 01-20 3l-2-1-4-1h-1l-3 2-2 3-4 5c-4 4-6 5-9 5l-10-2-13-2c-3 0-7 1-9 4-3 3-4 6-5 10l-1 6-1 5-2 1h-1l-1 1c-4-1-8-4-11-6l-7-8c-2-2-5-2-7-2l-7-1c-4 0-6-1-7-2s-2-2-2-6l-1-1-2-1c-4 0-9 4-13 7-5 3-9 6-13 6a73 73 0 01-29-10l-1-1h-1l-9 6c-2 3-5 5-7 5s-3-1-3-2l-1-5 1-7 2-15-1-7c-1-4-4-6-7-8l-10-3-6-2c-2 0-4 1-5 3-2 1-2 4-3 6l-2 7-6 2-4 3-2 3-1 3h-1l-2-1-1-4 1-12-1-1a97 97 0 01-16-5l-1-1 1-5-1-1-8-3-3-1-1-1v-1l1-2 1-1v-1l1-1 3-5c2-3 4-4 6-5 2-2 5-3 6-6l2-7c-1-6-5-11-5-17l-1-3 1-9c0-3 0-5-2-8l6-3c2-2 5-4 5-7l-1-3-3-3-3-2-1-4-1-6-5-5 1-1c0-5 0-9 2-12s3-7 7-10l10-2c4 0 7 0 11-2l1-2c-3-7-8-15-14-19l-1-1h-1-1l-2-3c-3-4-5-6-5-10v-3l-1-3-2-1z"  />
                     <g transform="translate(-850,-150)">
                         <text x="1580" y="370">Джанкой</text> 
                         <circle cx="1610" cy="400" r="15" />
                    </g> 
                </g> 
    </svg>              

    完整代码: Codepen

    虽然我设法用 477k ==> 25k 优化了源代码,但代码不适合片段

    • 3
  2. Sevastopol'
    2022-04-10T00:48:07Z2022-04-10T00:48:07Z

    地图被插入为带有图片的文件,使用标签<img>,通过src.

    position表示城市的点(标记)通过使用属性和值相对于地图图像的绝对定位方法放置在地图上absolute。

    带有城市名称的工具提示(工具提示)的外观是通过使用伪类将鼠标光标悬停在标记上来实现的:hover。

    div {
      position: relative; width: 800px; height: 506px;
    }
    
    span {
      display: block; position: absolute; width: 10px; height: 10px;
      background-color: gold; border-radius: 10px; cursor: pointer;
    }
    
    span:hover::before {
      content: ""; position: absolute; top: -10px; left: -10px; width: 30px; height: 30px;
      border-radius: 30px; background-color: gold;
      animation: animate 1.5s infinite normal ease-out;
    }
    
    @keyframes animate {
      from {transform: scale(0); opacity: .5}
      to {transform: scale(2); opacity: 0;}
    }
    
    .aa {top: 440px; left: 220px;}
    .bb {top: 320px; left: 360px;}
    .cc {top: 260px; left: 170px;}
    .dd {top: 320px; left: 545px;}
    .ee {top: 220px; left: 750px;}
    .ff {top: 453px; left: 333px;}
    
    i {
      display: block; position: absolute; left: 5px; bottom: 5px;
      background: gold; padding: 1px 5px;
      border: 1px solid white; border-radius: 2px;
      font-style: normal; font-size: 14px; font-family: monospace;
      opacity: 0;
      transform: rotate( -90deg) scale(0);
      transform-origin: 5px bottom;
      transition: all .15s ease-out;
    }
    span:hover i {opacity: 1; transform: rotate(0deg) scale(1);}
    <div>
      <img src="https://isstatic.askoverflow.dev/0lfnZ.jpg">
      <span class="aa"><i>Севастополь</i></span>
      <span class="bb"><i>Симферополь</i></span>
      <span class="cc"><i>Евпатория</i></span>
      <span class="dd"><i>Феодосия</i></span>
      <span class="ee"><i>Керчь</i></span>
      <span class="ff"><i>Ялта</i></span>
    </div>

    • 1

相关问题

  • 第二个 Instagram 按钮的 CSS 属性

  • 由于模糊,内容不可见

  • 弹出队列。消息显示不正确

  • 是否可以在 for 循环中插入提示?

  • 如何将 JSON 请求中的信息输出到数据表 Vuetify vue.js?

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    表格填充不起作用

    • 2 个回答
  • Marko Smith

    提示 50/50,有两个,其中一个是正确的

    • 1 个回答
  • Marko Smith

    在 PyQt5 中停止进程

    • 1 个回答
  • Marko Smith

    我的脚本不工作

    • 1 个回答
  • Marko Smith

    在文本文件中写入和读取列表

    • 2 个回答
  • Marko Smith

    如何像屏幕截图中那样并排排列这些块?

    • 1 个回答
  • Marko Smith

    确定文本文件中每一行的字符数

    • 2 个回答
  • Marko Smith

    将接口对象传递给 JAVA 构造函数

    • 1 个回答
  • Marko Smith

    正确更新数据库中的数据

    • 1 个回答
  • Marko Smith

    Python解析不是css

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5