演示:http : //jsfiddle.net/p7Lze6nh/
使用Raphael JS 2.1.2,我试图在单击元素时禁用文本突出显示。它可以在Chrome上运行,但由于某些原因不能在IE上运行。我目前没有FF在这台笔记本电脑上进行测试。
该代码相对简单-
var paper = Raphael(0, 0, 125, 125);
paper.canvas.style.backgroundColor = "Black";
var a = 0;
text1 = paper.text(10, 10, a).attr({"text-anchor":"start", fill:"white"});
rect1 = paper.rect(10, 50, 50, 50).attr({fill:"white"});
rect1.click(function(){
inc()
});
function inc() {
a++;
text1.attr({text: a});
}
我尝试使用“用户选择:无”和其他示例,这些示例通过包含该文件的div的示例找到了其他CSS规则,但是没有用。我也尝试过使用
text1.userSelect = "none";
...和其他人直接进入javascript,但我也没得到任何帮助。我记得Cookie Clicker遇到此问题,但似乎无法在代码中找到解决方案。但是,它也使用画布而不是Raphael。
用户选择应该可以正常运行,但不能采用所示格式。您不能只设置这样的对象变量。
使用CSS样式,可以像这样完成...
text {
-moz-user-select: none;
-webkit-user-select: none;
}
和直接不同的版本设置类
.donthighlight {
-moz-user-select: none;
-webkit-user-select: none;
}
text1.node.setAttribute("class","donthighlight");
我想要警惕一些较旧的浏览器可能不支持此功能,这是经常使用Raphael的原因,并将CSS扩展为包括其他浏览器。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句