javascript - 更改 <svg> 对象路径的笔划不透明度

标签 javascript jquery svg d3.js

简而言之 - 我试图通过将鼠标悬停在左侧的标题之一上来更改路径中的笔划不透明度(您会看到“presidio”标题有一个链接) 到目前为止我见过的 JQuery/javascript 答案都不起作用。

我尝试过的最新片段是:

d3.select('.presidio').on('mouseover', function(){
  console.log('hey!');
  var object = document.getElementById("presidio");
  object.setAttribute("stroke-opacity", 1);
});

svg 很大,因此将其粘贴到此处需要一百万年的时间才能阅读。但如果你想检查这里的 svg 元素:http://www.petegetscreative.com/hoods/hoods.html

最佳答案

要更改 id 为“presidio”的元素的不透明度:

d3.select('#presidio').style("stroke-opacity", "1");

为所有具有“presidio”类的元素添加鼠标悬停效果

d3.selectAll('.presidio').on('mouseover', function(){
  d3.select(this).style("stroke-opacity", "1"); })

关于javascript - 更改 <svg> 对象路径的笔划不透明度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20449609/

相关文章:

javascript - 如果 Jquery 元素的属性值为 1 或更高,则对其进行排序并放置在底部

javascript - 获取 JSON 文件的 AJAX 调用返回空值

php - PHP foreach 循环中的 JQuery $.post

页面刷新时 jQuery 未定义

javascript - 如何设置 D3.js svg 的背景颜色?

javascript - createElement() 未显示在查看源代码中

javascript - 谷歌地图 : how to find all of the markers inside the map by using gmaps. js

javascript - 如何检测 fabricJS Canvas 上的变化?

css - 是否可以在透明矢量/svg 周围添加 1px 边框?

html - 我可以更改 <g> 的大小和边距吗?或者 firefox 有错误?