简体   繁体   English

悬停在标记上时不要更改鼠标图标

[英]don't change mouse icon when hovering over a marker

I have a map with a number of markers.我有一张带有许多标记的地图。 When a user clicks on one marker information for that marker is displayed on a side pane.当用户单击一个标记时,该标记的信息会显示在侧窗格中。 To accomplish that I have added 'click' listeners to the markers and also store marker identifiers more or less as suggested in this SO answer .为了实现这一点,我在标记中添加了“点击”侦听器,并或多或少地存储了标记标识符, 如此 SO answer 中所建议的。

Now, on certain modes I don't want the markers to be clickable (but still want them to appear on the screen).现在,在某些模式下,我不希望标记可点击(但仍希望它们出现在屏幕上)。 It is easy for me to remove all the 'click' listeners.我很容易删除所有“点击”侦听器。 However, when I hover over them with my mouse, the icon does change from the "open palm" to the "pointed hand" confusing the user.然而,当我用鼠标悬停在它们上面时,图标确实从“张开的手掌”变成了“尖头”,让用户感到困惑。 Upon investigating I see that the canvas class normally has the leaflet-zoom-animated class, but when I hover over a marker, the leaflet-interactive class gets added.经过调查,我发现画布类通常具有leaflet-zoom-animated类,但是当我将鼠标悬停在标记上时,会添加leaflet-interactive类。 I can change that cursor using, eg:我可以使用例如更改该光标:

.leaflet-interactive {
    cursor: crosshair !important;
}

... but this has two problems: ...但这有两个问题:

  1. it's not something I can toggle on and off depending on the various user interaction modes my application finds itself in这不是我可以根据我的应用程序所处的各种用户交互模式打开和关闭的东西
  2. it's still jarring because the cursor does change and, further, I can't change it to the open palm cursor that Leaflet is normally using, since that's a non-default cursor and it's not clear to me how to access it.它仍然很刺耳,因为光标确实发生了变化,此外,我无法将其更改为 Leaflet 通常使用的打开手掌光标,因为这是一个非默认光标,我不清楚如何访问它。

If you can remove the click listener, I suppose that you can also add a css class to your marker.如果您可以删除单击侦听器,我想您还可以向标记中添加一个 css 类。 Here is an example http://jsfiddle.net/Mossart/w9830at1/7/ (look at the top marker)这是一个示例http://jsfiddle.net/Mossart/w9830at1/7/ (查看顶部标记)

var breakside = [45.571601194035345, -122.65673562884331];
var marker1 = L.marker(breakside).addTo(map);
marker1._icon.classList.add("not-clickable");

CSS: CSS:

.not-clickable {
  cursor: grab;
}

This works for L.circleMarker objects on a canvas renderer:这适用于画布渲染器上的L.circleMarker对象:

marker.options.interactive = false;

Curiously, it doesn't work on a non-canvas renderer.奇怪的是,它不适用于非画布渲染器。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 jQuery 将鼠标悬停在相邻文本上时更改图标颜色 - Change Color of Icon When Hovering Over Adjacent Text With jQuery 鼠标悬停时更改图片 - Change picture when hovering with mouse 为什么 <li> 元素悬停在图像上后将鼠标悬停在元素上时,颜色和宽度不会改变吗? - Why does the <li> element not change color and width when I hover the mouse over it after hovering over the image? 将鼠标悬停在侧边栏中的项目上时,gmaps4rails会更改标记颜色 - gmaps4rails change marker color when hovering over item in sidebar 将鼠标悬停在图标上时按钮文字模糊 - Button text blurring when hovering over an icon 将鼠标悬停在菜单按钮上时要移动的图标 - Icon to move when hovering over a menu button 将鼠标悬停在图像上以显示按钮,并将鼠标悬停在实际按钮上时不会触发 - Hover over image to show buttons and don't trigger when hovering over actual buttons 在图像上插入文本并通过将鼠标悬停在 (JavaScript) 上来更改文本 - Insert text over an image and change the text by hovering the mouse over (JavaScript) 如何在鼠标按下时根据悬停在哪个单元格上更改 html 表格单元格的颜色? - How to change color of an html table cell when mouse is down, based on which cell it is hovering over? 在Video.js中,当鼠标悬停在视频上方时,在哪里可以更改大播放按钮的颜色? - In Video.js, where can I change the big play button color when the mouse is hovering over the video?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM