[英]How do I display text for touch events in D3.js?
I have a map with areas on it where it displays text when the mouse hovers over it (using touchstart and touchend events).我有一张地图,上面有一个区域,当鼠标悬停在它上面时它会显示文本(使用 touchstart 和 touchend 事件)。 However, on my iPad the text does not display although the areas change color when I touch it.
但是,在我的 iPad 上,尽管触摸时区域会改变颜色,但文本并未显示。 Anyone know how to make it display the text?
有谁知道如何让它显示文本?
function create_canada(canada) {
var provinces = svg.append("g")
.attr("class", "provinces")
.selectAll("path")
.data(topojson.object(canada, canada.objects.provinces).geometries)
.enter().append("path")
.attr("class", "province")
.attr("d", path)
.style("fill", function(d) {
return "#"+Math.floor(Math.random()*16777215).toString(16);
})
.style("opacity","0.7")
.on("touchstart", function(d) {
colour = d3.select(this).style("fill");
d3.select(this).style("fill", "red");
}) // end mouseover
.on("touchend", function(d) {
d3.select(this).style("fill", function(d) {
return colour;
}); // end mouseout
}); // end var provinces
provinces.append("svg:title")
.text(function(d) {
return (d.id + " " + (get_Percapita(d)) + " per million"); // d.id is the Province name
});
return provinces;
you should add a tspan in your text like this :你应该像这样在你的文本中添加一个tspan :
<text><tspan>My text</tspan></text>
and the touchstart
or touchend
action should work fine.并且
touchstart
或touchend
动作应该可以正常工作。 See https://developer.mozilla.org/en-US/docs/Web/SVG/Element/tspan请参阅https://developer.mozilla.org/en-US/docs/Web/SVG/Element/tspan
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.