【发布时间】:2016-06-15 04:15:22
【问题描述】:
我正在使用 D3,我想在鼠标悬停时模糊图像。
我在图片后面直接放置了一个rect 元素,并在图片上设置了pointer-events: none,在矩形上设置了pointer-events: all。这可以很好地捕获鼠标悬停事件,但我无法使图像模糊。
这是我设置图像及其rect 元素的 D3 代码:
var newImages = images.enter()
.append("g")
.attr("class", "image");
newImages.append("svg:image")
.attr('class', 'image-body')
.attr('x', 0).attr('y', 20)
.attr("xlink:href", function(d, i) {
return "http://placekitten.com/150/200";
});
newImages.append("rect")
.attr('class', 'image-background')
.attr('x', 0).attr('y', 20);
还有 CSS 不起作用:
.image-background {
stroke: black;
stroke-width: 1px;
fill: none;
cursor: pointer;
pointer-events: all;
width: 150px;
height: 200px;
}
.image-background:hover {
-webkit-filter: blur(1px);
-moz-filter: blur(1px);
-o-filter: blur(1px);
-ms-filter: blur(1px);
filter: blur(1px);
}
.image-body {
pointer-events:none;
width: 150px;
height: 200px;
}
如果我将fill: blue 添加到image-background: hover,那看起来就好了。是否可以添加模糊滤镜?
这是我的 JSFiddle:https://jsfiddle.net/p4bfsvw9/2/
【问题讨论】:
-
我们不能让图像像这样模糊
d3.select('.image-body').transition().duration(2000).style("opacity", 0);像这样jsfiddle.net/3bwujq71 -
@Cyril 降低了不透明度,但不会模糊......我想这可以作为后备,谢谢。