- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 SVG 图像,我在其中放置了更多图像(它们也是 svg 图形)。我需要在鼠标悬停时更改它们的颜色。
现在我正在尝试使用 d3js 进行以下操作,但它不起作用。
graph
.selectAll('g')
.data(Operators)
.enter()
.append('g')
.selectAll('image')
.data(function (d) {
//console.log('image d', d);
return d;
})
.enter()
.append('image')
.attr('id', function (d) {
return d.name;
})
.attr('x', function (d) {
return d.x;
})
.attr('y', function (d) {
return d.y ;
})
.attr('width', function (d) {
return d.width;
})
.attr('height', function (d) {
return d.height;
})
.attr("xlink:href", function (d) {
return base_url + "/assets/svg/" + d.src;
})
.style('fill', function (d) {
//return d.hoverColor;
})
.on('mouseover', function (d) {
var img = d3.select(this);
console.log('hoverColor: ', d.hoverColor);
img.style('fill', d.hoverColor);
})
这是一个示例 SVG 图像
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 16.2.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1 Tiny//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-tiny.dtd">
<svg version="1.1" baseProfile="tiny" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
x="0px" y="0px" width="32px" height="32px" viewBox="0 0 32 32" xml:space="preserve">
<g>
<g>
<path fill="#FFFFFF" d="M4.628,26.186L2.305,24l1.037-0.977C0.451,21.527,0,19.656,0,19.656v4.84c0,0,1.18,3.527,8.637,4.558
C6.25,27.691,4.749,26.299,4.628,26.186z"/>
</g>
<g>
<path fill="#FFFFFF" d="M17.957,16.254c1.014,0,1.993,0.109,2.938,0.286C25.23,15.116,26,12.761,26,12.761V7.923
c0,0-1.286,5.202-13.021,5.202C1.246,13.125,0,7.923,0,7.923v4.838c0,0,1.47,4.397,11.502,4.806
C13.405,16.809,15.597,16.254,17.957,16.254z"/>
</g>
<g>
<path fill="#FFFFFF" d="M26,18.277V13.73c0,0-0.447,1.796-3.195,3.278C23.961,17.357,25.031,17.799,26,18.277z"/>
<path fill="#FFFFFF" d="M4.628,21.814c0.128-0.119,1.812-1.67,4.446-3.104C0.956,17.719,0,13.729,0,13.729v4.839
c0,0,0.689,2.067,4.357,3.5L4.628,21.814z"/>
</g>
<circle fill="#FFFFFF" cx="17.957" cy="24" r="4.747"/>
<path fill="#FFFFFF" d="M17.957,30.248c-6.744,0-12.078-4.944-12.301-5.154L4.494,24l1.162-1.092
c0.224-0.211,5.558-5.154,12.301-5.154c6.74,0,12.075,4.943,12.299,5.154L31.418,24l-1.162,1.094
C30.032,25.304,24.697,30.248,17.957,30.248z M9.083,23.998c1.788,1.285,5.132,3.25,8.875,3.25c3.735,0,7.079-1.961,8.869-3.248
c-1.79-1.285-5.132-3.246-8.869-3.246C14.197,20.754,10.865,22.713,9.083,23.998z"/>
<g>
<g>
<path fill="#FFFFFF" d="M12.89,2.497c-4.141,0-7.638,1.487-7.638,3.248c0,1.761,3.498,3.249,7.638,3.249
c4.139,0,7.639-1.488,7.639-3.249C20.527,3.985,17.029,2.497,12.89,2.497z M12.89,7.579c-2.211,0-3.943-0.805-3.943-1.833
c0-1.027,1.732-1.833,3.943-1.833s3.943,0.805,3.943,1.833C16.833,6.774,15.101,7.579,12.89,7.579z"/>
<path fill="#FFFFFF" d="M12.89,4.185c-1.99,0-3.671,0.714-3.671,1.561c0,0.847,1.681,1.562,3.671,1.562
c1.99,0,3.67-0.715,3.67-1.562C16.561,4.899,14.88,4.185,12.89,4.185z"/>
<path fill="#FFFFFF" d="M12.89,0C5.771,0,0,2.572,0,5.745c0,3.173,5.771,5.747,12.89,5.747c7.119,0,12.889-2.573,12.889-5.747
C25.779,2.571,20.009,0,12.89,0z M12.89,10.537c-5.779,0-10.307-2.105-10.307-4.792S7.11,0.954,12.89,0.954
c5.78,0,10.307,2.104,10.307,4.791S18.669,10.537,12.89,10.537z"/>
</g>
</g>
</g>
</svg>
谁能帮帮我?
最佳答案
使用简单的 CSS:
向您的路径元素添加一个类名,如 class="svgimg"
然后在 css
svg:hover .svgimg { fill: darkslateblue; }
找到这个演示: DEMO:
关于javascript - 更改 svg 图像的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33806211/
我正在尝试学习 Knockout 并尝试创建一个照片 uploader 。我已成功将一些图像存储在数组中。现在我想回帖。在我的 knockout 码(Javascript)中,我这样做: 我在 Jav
我正在使用 php 编写脚本。我的典型问题是如何在 mysql 中添加一个有很多替代文本和图像的问题。想象一下有机化学中具有苯结构的描述。 最有效的方法是什么?据我所知,如果我有一个图像,我可以在数据
我在两个图像之间有一个按钮,我想将按钮居中到图像高度。有人可以帮帮我吗? Entrar
下面的代码示例可以在这里查看 - http://dev.touch-akl.com/celebtrations/ 我一直在尝试做的是在 Canvas 上绘制 2 个图像(发光,然后耀斑。这些图像的链接
请检查此https://jsfiddle.net/rhbwpn19/4/ 图像预览对于第一篇帖子工作正常,但对于其他帖子则不然。 我应该在这里改变什么? function readURL(input)
我对 Canvas 有疑问。我可以用单个图像绘制 Canvas ,但我不能用单独的图像绘制每个 Canvas 。- 如果数据只有一个图像,它工作正常,但数据有多个图像,它不工作你能帮帮我吗? va
我的问题很简单。如何获取 UIImage 的扩展类型?我只能将图像作为 UIImage 而不是它的名称。图像可以是静态的,也可以从手机图库甚至文件路径中获取。如果有人可以为此提供一点帮助,将不胜感激。
我有一个包含 67 个独立路径的 SVG 图像。 是否有任何库/教程可以为每个路径创建单独的光栅图像(例如 PNG),并可能根据路径 ID 命名它们? 最佳答案 谢谢大家。我最终使用了两个答案的组合。
我想将鼠标悬停在一张图片(音乐专辑)上,然后播放一张唱片,所以我希望它向右移动并旋转一点,当它悬停时我希望它恢复正常动画片。它已经可以向右移动,但我无法让它随之旋转。我喜欢让它尽可能简单,因为我不是编
Retina iOS 设备不显示@2X 图像,它显示 1X 图像。 我正在使用 Xcode 4.2.1 Build 4D502,该应用程序的目标是 iOS 5。 我创建了一个测试应用(主/细节)并添加
我正在尝试从头开始以 Angular 实现图像 slider ,并尝试复制 w3school基于图像 slider 。 下面我尝试用 Angular 实现,谁能指导我如何使用 Angular 实现?
我正在尝试获取图像的图像数据,其中 w= 图像宽度,h = 图像高度 for (int i = x; i imageData[pos]>0) //Taking data (here is the pr
我的网页最初通过在 javascript 中动态创建图像填充了大约 1000 个缩略图。由于权限问题,我迁移到 suPHP。现在不用标准 标签本身 我正在通过这个 php 脚本进行检索 $file
我正在尝试将 python opencv 图像转换为 QPixmap。 我按照指示显示Page Link我的代码附在下面 img = cv2.imread('test.png')[:,:,::1]/2
我试图在这个 Repository 中找出语义分割数据集的 NYU-v2 . 我很难理解图像标签是如何存储的。 例如,给定以下图像: 对应的标签图片为: 现在,如果我在 OpenCV 中打开标签图像,
import java.util.Random; class svg{ public static void main(String[] args){ String f="\"
我有一张 8x8 的图片。 (位图 - 可以更改) 我想做的是能够绘制一个形状,给定一个 Path 和 Paint 对象到我的 SurfaceView 上。 目前我所能做的就是用纯色填充形状。我怎样才
要在页面上显示图像,你需要使用源属性(src)。src 指 source 。源属性的值是图像的 URL 地址。 定义图像的语法是: 在浏览器无法载入图像时,替换文本属性告诉读者她们失去的信息。此
**MMEditing是基于PyTorch的图像&视频编辑开源工具箱,支持图像和视频超分辨率(super-resolution)、图像修复(inpainting)、图像抠图(matting)、
我正在尝试通过资源文件将图像插入到我的程序中,如下所示: green.png other files 当我尝试使用 QImage 或 QPixm
我是一名优秀的程序员,十分优秀!