将鼠标悬停在一个点上可显示弹出图像

佐伊贝斯特

我最近从 amcharts.com 下载了一个模板代码,这样我就可以在我的网站上放一张地图。该代码在我设置纬度和经度的任何位置放置了一些脉动点,我还可以为每个点添加一个标题。但是,每当我尝试添加另一个参数(例如 URL)时,都会出现错误。在这一点上,我试图让鼠标悬停在每个点上将创建该位置的弹出图像。我无法弄清楚如何让弹出窗口工作,并确保每个点都有不同的弹出图像。这是我一直在使用的 codepen 的链接。

https://codepen.io/ZoeyEllen/pen/yvXvZX?editors=1111

我已经做了很多谷歌搜索,我发现了一些关于 javascript、html 和 css 的不同建议,但我尝试过的似乎没有任何效果。这是我到目前为止的代码:

var map = AmCharts.makeChart( "chartdiv", {
  "type": "map",
  "theme": "light",
  "projection": "mercator",

  "imagesSettings": {
    "rollOverColor": "#089282",
    "rollOverScale": 5,
    "selectedScale": 5,
    "selectedColor": "#089282",
    "color": "#13564e"
  },

  "areasSettings": {
    "unlistedAreasColor": "#15A892"
  },

  "dataProvider": {
    "map": "worldLow",
    "images": [ {
      "zoomLevel": 5,
      "scale": 0.5,
      "title": "Hawaii, USA",
      "latitude": 19.8968,
      "longitude": -155.5828
    }, {
      "zoomLevel": 5,
      "scale": 0.5,
      "title": "Galápagos Islands",
      "latitude": -0.8675,
      "longitude": -89.4364
   }, {
      "zoomLevel": 5,
      "scale": 0.5,
      "title": "Italy",
      "latitude": 41.9028,
      "longitude": 12.4964
    }, {
      "zoomLevel": 5,
      "scale": 0.5,
      "title": "Greece",
      "latitude": 37.9838,
      "longitude": 23.7275
      }, {
      "zoomLevel": 5,
      "scale": 0.5,
      "title": "The Bahamas",
      "latitude": 24.9314,
      "longitude": -76.1900
    }, {
      "zoomLevel": 5,
      "scale": 0.5,
      "title": "South Florida, USA",
      "latitude": 26.1224,
      "longitude": -80.1373
        }, {
      "zoomLevel": 5,
      "scale": 0.5,
      "title": "Canada",
      "latitude": 45.5017,
      "longitude": -73.5673
          }, {
      "zoomLevel": 5,
      "scale": 0.5,
      "title": "Washington State, USA",
      "latitude": 47.6062,
      "longitude": -122.3321
      }, {
      "zoomLevel": 5,
      "scale": 0.5,
      "title": "California, USA",
      "latitude": 34.0522,
      "longitude": -118.2437
          }, {
      "zoomLevel": 5,
      "scale": 0.5,
      "title": "Illinois, USA",
      "latitude": 41.8781,
      "longitude": -87.6298
        }, {
      "zoomLevel": 5,
      "scale": 0.5,
      "title": "Costa Rica",
      "latitude": 9.7489,
      "longitude": -83.7534
           }, {
      "zoomLevel": 5,
      "scale": 0.5,
      "title": "North Carolina, USA",
      "latitude": 35.7596,
      "longitude": -79.0193
    } ]
  }
} );

// add events to recalculate map position when the map is moved or zoomed
map.addListener( "positionChanged", updateCustomMarkers );

// this function will take current images on the map and create HTML elements for them
function updateCustomMarkers( event ) {
  // get map object
  var map = event.chart;

  // go through all of the images
  for ( var x in map.dataProvider.images ) {
    // get MapImage object
    var image = map.dataProvider.images[ x ];

    // check if it has corresponding HTML element
    if ( 'undefined' == typeof image.externalElement )
      image.externalElement = createCustomMarker( image );

    // reposition the element accoridng to coordinates
    var xy = map.coordinatesToStageXY( image.longitude, image.latitude );
    image.externalElement.style.top = xy.y + 'px';
    image.externalElement.style.left = xy.x + 'px';
  }
}

// this function creates and returns a new marker element
function createCustomMarker( image ) {
  // create holder
  var holder = document.createElement( 'div' );
  holder.className = 'map-marker';
  holder.title = image.title;
  holder.style.position = 'absolute';

  // maybe add a link to it?
  if ( undefined != image.url ) {
    holder.onclick = function() {
      window.location.href = image.url;
    };
    holder.className += ' map-clickable';
  }

  // create dot
  var dot = document.createElement( 'div' );
  dot.className = 'dot';
  holder.appendChild( dot );

  // create pulse
  var pulse = document.createElement( 'div' );
  pulse.className = 'pulse';
  holder.appendChild( pulse );

  // append the marker to the map container
  image.chart.chartDiv.appendChild( holder );
holder.onmouseover = function(){
     console.log(image.title);
  }

  return holder;
}
#chartdiv {
  width: 100%;
  height: 500px;
}

.map-marker {
    /* adjusting for the marker dimensions
    so that it is centered on coordinates */
    margin-left: -8px;
    margin-top: -8px;
}
.map-marker.map-clickable {
    cursor: pointer;
}
.pulse {
    width: 10px;
    height: 10px;
    border: 3px solid #FFB6C1;
    -webkit-border-radius: 20px;
    -moz-border-radius: 20px;
    border-radius: 20px;
    background-color: #ff69b4;
    z-index: 10;
    position: absolute;
  }
.map-marker .dot {
    border: 3px solid #ff69b4;
    background: transparent;
    -webkit-border-radius: 40px;
    -moz-border-radius: 40px;
    border-radius: 40px;
    height: 50px;
    width: 50px;
    -webkit-animation: pulse 3s ease-out;
    -moz-animation: pulse 3s ease-out;
    animation: pulse 3s ease-out;
    -webkit-animation-iteration-count: infinite;
    -moz-animation-iteration-count: infinite;
    animation-iteration-count: infinite;
    position: absolute;
    top: -20px;
    left: -20px;
    z-index: 1;
    opacity: 0;
  }
  @-moz-keyframes pulse {
   0% {
      -moz-transform: scale(0);
      opacity: 0.0;
   }
   25% {
      -moz-transform: scale(0);
      opacity: 0.1;
   }
   50% {
      -moz-transform: scale(0.1);
      opacity: 0.3;
   }
   75% {
      -moz-transform: scale(0.5);
      opacity: 0.5;
   }
   100% {
      -moz-transform: scale(1);
      opacity: 0.0;
   }
  }
  @-webkit-keyframes "pulse" {
   0% {
      -webkit-transform: scale(0);
      opacity: 0.0;
   }
   25% {
      -webkit-transform: scale(0);
      opacity: 0.1;
   }
   50% {
      -webkit-transform: scale(0.1);
      opacity: 0.3;
   }
   75% {
      -webkit-transform: scale(0.5);
      opacity: 0.5;
   }
   100% {
      -webkit-transform: scale(1);
      opacity: 0.0;
   }
    
</style>
<script src="https://www.amcharts.com/lib/3/ammap.js"></script>
<script src="https://www.amcharts.com/lib/3/maps/js/worldLow.js"></script>
<script src="https://www.amcharts.com/lib/3/plugins/export/export.min.js"></script>
<link rel="stylesheet" href="https://www.amcharts.com/lib/3/plugins/export/export.css" type="text/css" media="all" />
<script src="https://www.amcharts.com/lib/3/themes/light.js"></script>
<div id="chartdiv"></div>

杰拉多·怀特

好的,所以我希望这就是你要找的。我添加了弹出窗口以显示在地图的中心。您可以为弹出窗口添加您的 css,但这演示了您想要的内容。

解释

HTML

<div>在 HTML 底部添加每个弹出窗口它们具有在图像对象和它们的类中引用的单独值,popup以提供您想要的样式

<div id="pop0" class="popup">A</div>

CSS

添加了两个类

  1. 弹出窗口:整体设置弹出窗口的样式

    .popup { 显示:无;位置:绝对;顶部:0;底部:0;右:0;左:0;保证金:自动;背景:红色;宽度:50px;高度:50px;}

  2. popon:与听众一起打开弹出窗口

    .popon { 显示:块;}

JS

在这里添加了两个不同的东西

首先,我pop在每个元素中添加了值来引用id每个点的所需弹出窗口

其次我添加了两个事件监听器

  1. MouseOver - 这会将类添加popon到点的弹出元素

    holder.onmouseover = function() { popup.classList.add('popon'); }

  2. MouseLeave - 这将删除popon点的弹出元素的类

    holder.onmouseleave = function() { popup.classList.remove('popon'); }

var map = AmCharts.makeChart("chartdiv", {
  "type": "map",
  "theme": "light",
  "projection": "mercator",

  "imagesSettings": {
    "rollOverColor": "#089282",
    "rollOverScale": 5,
    "selectedScale": 5,
    "selectedColor": "#089282",
    "color": "#13564e"
  },

  "areasSettings": {
    "unlistedAreasColor": "#15A892"
  },

  "dataProvider": {
    "map": "worldLow",
    "images": [{
      "zoomLevel": 5,
      "scale": 0.5,
      "title": "Hawaii, USA",
      "latitude": 19.8968,
      "longitude": -155.5828,
      "pop": "pop0"
    }, {
      "zoomLevel": 5,
      "scale": 0.5,
      "title": "Galápagos Islands",
      "latitude": -0.8675,
      "longitude": -89.4364,
      "pop": "pop1"
    }, {
      "zoomLevel": 5,
      "scale": 0.5,
      "title": "Italy",
      "latitude": 41.9028,
      "longitude": 12.4964,
      "pop": "pop2"
    }, {
      "zoomLevel": 5,
      "scale": 0.5,
      "title": "Greece",
      "latitude": 37.9838,
      "longitude": 23.7275,
      "pop": "pop3"
    }, {
      "zoomLevel": 5,
      "scale": 0.5,
      "title": "The Bahamas",
      "latitude": 24.9314,
      "longitude": -76.1900,
      "pop": "pop4"
    }, {
      "zoomLevel": 5,
      "scale": 0.5,
      "title": "South Florida, USA",
      "latitude": 26.1224,
      "longitude": -80.1373,
      "pop": "pop5"
    }, {
      "zoomLevel": 5,
      "scale": 0.5,
      "title": "Canada",
      "latitude": 45.5017,
      "longitude": -73.5673,
      "pop": "pop6"
    }, {
      "zoomLevel": 5,
      "scale": 0.5,
      "title": "Washington State, USA",
      "latitude": 47.6062,
      "longitude": -122.3321,
      "pop": "pop7"
    }, {
      "zoomLevel": 5,
      "scale": 0.5,
      "title": "California, USA",
      "latitude": 34.0522,
      "longitude": -118.2437,
      "pop": "pop8"
    }, {
      "zoomLevel": 5,
      "scale": 0.5,
      "title": "Illinois, USA",
      "latitude": 41.8781,
      "longitude": -87.6298,
      "pop": "pop9"
    }, {
      "zoomLevel": 5,
      "scale": 0.5,
      "title": "Costa Rica",
      "latitude": 9.7489,
      "longitude": -83.7534,
      "pop": "pop10"
    }, {
      "zoomLevel": 5,
      "scale": 0.5,
      "title": "North Carolina, USA",
      "latitude": 35.7596,
      "longitude": -79.0193,
      "pop": "pop11"
    }]
  }
});


// add events to recalculate map position when the map is moved or zoomed
map.addListener("positionChanged", updateCustomMarkers);

// this function will take current images on the map and create HTML elements for them
function updateCustomMarkers(event) {
  // get map object
  var map = event.chart;

  // go through all of the images
  for (var x in map.dataProvider.images) {
    // get MapImage object
    var image = map.dataProvider.images[x];

    // check if it has corresponding HTML element
    if ('undefined' == typeof image.externalElement)
      image.externalElement = createCustomMarker(image);

    // reposition the element accoridng to coordinates
    var xy = map.coordinatesToStageXY(image.longitude, image.latitude);
    image.externalElement.style.top = xy.y + 'px';
    image.externalElement.style.left = xy.x + 'px';
  }
}

// this function creates and returns a new marker element
function createCustomMarker(image) {
  // create holder
  var holder = document.createElement('div');
  holder.className = 'map-marker';
  holder.title = image.title;
  holder.style.position = 'absolute';

  // maybe add a link to it?
  if (undefined != image.url) {
    holder.onclick = function() {
      window.location.href = image.url;
    };
    holder.className += ' map-clickable';
  }

  // create dot
  var dot = document.createElement('div');
  dot.className = 'dot';
  holder.appendChild(dot);

  // create pulse
  var pulse = document.createElement('div');
  pulse.className = 'pulse';
  holder.appendChild(pulse);

  // append the marker to the map container
  image.chart.chartDiv.appendChild(holder);


  //Mouseover listener
  var popup = document.getElementById(image.pop);
  holder.onmouseover = function() {
    popup.classList.add('popon');
  }
  holder.onmouseleave = function() {
    popup.classList.remove('popon');
  }

  return holder;
}
  #chartdiv {
  width: 100%;
  height: 500px;
}

.map-marker {
  /* adjusting for the marker dimensions
    so that it is centered on coordinates */
  margin-left: -8px;
  margin-top: -8px;
}

.map-marker.map-clickable {
  cursor: pointer;
}

.pulse {
  width: 10px;
  height: 10px;
  border: 3px solid #FFB6C1;
  -webkit-border-radius: 20px;
  -moz-border-radius: 20px;
  border-radius: 20px;
  background-color: #ff69b4;
  z-index: 10;
  position: absolute;
}

.map-marker .dot {
  border: 3px solid #ff69b4;
  background: transparent;
  -webkit-border-radius: 40px;
  -moz-border-radius: 40px;
  border-radius: 40px;
  height: 50px;
  width: 50px;
  -webkit-animation: pulse 3s ease-out;
  -moz-animation: pulse 3s ease-out;
  animation: pulse 3s ease-out;
  -webkit-animation-iteration-count: infinite;
  -moz-animation-iteration-count: infinite;
  animation-iteration-count: infinite;
  position: absolute;
  top: -20px;
  left: -20px;
  z-index: 1;
  opacity: 0;
}

.popup {
  display: none;
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  left: 0;
  margin: auto;
  background: red;
  width: 50px;
  height: 50px;
}

.popon {
  display: block;
}

@-moz-keyframes pulse {
  0% {
    -moz-transform: scale(0);
    opacity: 0.0;
  }
  25% {
    -moz-transform: scale(0);
    opacity: 0.1;
  }
  50% {
    -moz-transform: scale(0.1);
    opacity: 0.3;
  }
  75% {
    -moz-transform: scale(0.5);
    opacity: 0.5;
  }
  100% {
    -moz-transform: scale(1);
    opacity: 0.0;
  }
}

@-webkit-keyframes "pulse" {
  0% {
    -webkit-transform: scale(0);
    opacity: 0.0;
  }
  25% {
    -webkit-transform: scale(0);
    opacity: 0.1;
  }
  50% {
    -webkit-transform: scale(0.1);
    opacity: 0.3;
  }
  75% {
    -webkit-transform: scale(0.5);
    opacity: 0.5;
  }
  100% {
    -webkit-transform: scale(1);
    opacity: 0.0;
  }
<script src="https://www.amcharts.com/lib/3/ammap.js"></script>
<script src="https://www.amcharts.com/lib/3/maps/js/worldLow.js"></script>
<script src="https://www.amcharts.com/lib/3/plugins/export/export.min.js"></script>
<link rel="stylesheet" href="https://www.amcharts.com/lib/3/plugins/export/export.css" type="text/css" media="all" />
<script src="https://www.amcharts.com/lib/3/themes/light.js"></script>
<div id="chartdiv"></div>
<div id="pop0" class="popup">A</div>
<div id="pop1" class="popup">B</div>
<div id="pop2" class="popup">C</div>
<div id="pop3" class="popup">D</div>
<div id="pop4" class="popup">E</div>
<div id="pop5" class="popup">F</div>
<div id="pop6" class="popup">G</div>
<div id="pop7" class="popup">H</div>
<div id="pop8" class="popup">I</div>
<div id="pop9" class="popup">J</div>
<div id="pop10" class="popup">K</div>
<div id="pop11" class="popup">L</div>

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

将鼠标悬停在ID上可显示另一个Div

来自分类Dev

当用户将鼠标悬停在另一个元素上时,无法显示弹出窗口元素

来自分类Dev

当用户将鼠标悬停在另一个元素上时,无法显示弹出窗口元素

来自分类Dev

将鼠标悬停在图像上并更改另一个

来自分类Dev

将鼠标悬停在一个元素上以显示其他元素

来自分类Dev

将鼠标悬停在另一个div上时如何显示div

来自分类Dev

将鼠标悬停在多个 div 上显示一个 div

来自分类Dev

当我将鼠标悬停在一个图像上时,该图像会显示到另一个Div或表列中吗?

来自分类Dev

将鼠标悬停在图像上时显示图像

来自分类Dev

将鼠标悬停在一个div上可触发效果悬停在另一个div上

来自分类Dev

将鼠标悬停在一个div上以显示另一个div

来自分类Dev

将鼠标悬停在导航栏上显示图像

来自分类Dev

将鼠标悬停在图像上时按钮显示

来自分类Dev

将鼠标悬停在导航栏上显示图像

来自分类Dev

鼠标悬停。保持课堂直到将鼠标悬停在另一个元素上

来自分类Dev

将鼠标悬停在一个元素上会显示div,而将鼠标悬停在一个元素上则会显示第二个第二个div

来自分类Dev

当有人将鼠标悬停在div上时显示另一个div

来自分类Dev

仅使用CSS将鼠标悬停在另一个div上时显示div

来自分类Dev

fullpage.js-将鼠标悬停在一个圆圈上显示所有工具提示

来自分类Dev

仅使用CSS将鼠标悬停在另一个div上时显示div

来自分类Dev

将鼠标悬停在<ul>上时,我要显示另一个<ul>

来自分类Dev

将鼠标悬停在DIV上,然后显示另一个div,而无需重新定位*

来自分类Dev

将鼠标悬停在选定的图像上时,将弹出选定的图像

来自分类Dev

将鼠标悬停在第一个div上时需要将鼠标悬停在第二个div上

来自分类Dev

将鼠标悬停在另一个div上时CSS更改div

来自分类Dev

通过CSS防止将鼠标悬停在第一个元素上

来自分类Dev

当我将鼠标悬停在ComboBox项上时引发一个事件

来自分类Dev

将鼠标悬停在另一个div上时更改div

来自分类Dev

CSS:将鼠标悬停在另一个元素上

Related 相关文章

  1. 1

    将鼠标悬停在ID上可显示另一个Div

  2. 2

    当用户将鼠标悬停在另一个元素上时,无法显示弹出窗口元素

  3. 3

    当用户将鼠标悬停在另一个元素上时,无法显示弹出窗口元素

  4. 4

    将鼠标悬停在图像上并更改另一个

  5. 5

    将鼠标悬停在一个元素上以显示其他元素

  6. 6

    将鼠标悬停在另一个div上时如何显示div

  7. 7

    将鼠标悬停在多个 div 上显示一个 div

  8. 8

    当我将鼠标悬停在一个图像上时,该图像会显示到另一个Div或表列中吗?

  9. 9

    将鼠标悬停在图像上时显示图像

  10. 10

    将鼠标悬停在一个div上可触发效果悬停在另一个div上

  11. 11

    将鼠标悬停在一个div上以显示另一个div

  12. 12

    将鼠标悬停在导航栏上显示图像

  13. 13

    将鼠标悬停在图像上时按钮显示

  14. 14

    将鼠标悬停在导航栏上显示图像

  15. 15

    鼠标悬停。保持课堂直到将鼠标悬停在另一个元素上

  16. 16

    将鼠标悬停在一个元素上会显示div,而将鼠标悬停在一个元素上则会显示第二个第二个div

  17. 17

    当有人将鼠标悬停在div上时显示另一个div

  18. 18

    仅使用CSS将鼠标悬停在另一个div上时显示div

  19. 19

    fullpage.js-将鼠标悬停在一个圆圈上显示所有工具提示

  20. 20

    仅使用CSS将鼠标悬停在另一个div上时显示div

  21. 21

    将鼠标悬停在<ul>上时,我要显示另一个<ul>

  22. 22

    将鼠标悬停在DIV上,然后显示另一个div,而无需重新定位*

  23. 23

    将鼠标悬停在选定的图像上时,将弹出选定的图像

  24. 24

    将鼠标悬停在第一个div上时需要将鼠标悬停在第二个div上

  25. 25

    将鼠标悬停在另一个div上时CSS更改div

  26. 26

    通过CSS防止将鼠标悬停在第一个元素上

  27. 27

    当我将鼠标悬停在ComboBox项上时引发一个事件

  28. 28

    将鼠标悬停在另一个div上时更改div

  29. 29

    CSS:将鼠标悬停在另一个元素上

热门标签

归档