借助 Raphael.js 脱颖而出并焕发光彩
编辑:写完我的问题后,我想到 toFront()
代码可能会在 DOM 中的不同位置重新创建该元素。当它首先删除该元素时,它可能会丢失 IE 和 Opera 附加的任何事件,因此是我的问题。我将致力于制定委托活动替代方案,但仍愿意接受建议。
我在拉斐尔纸上画了一些形状,当你将鼠标悬停在它们上方时,它们应该会发光。然而,由于这些形状彼此直接相邻,为了确保您看到周围的发光,我必须将当前形状放在前面。
当前元素位于顶部,因此它的发光将出现在相邻形状的顶部。我的代码在 Webkit 和 Firefox 中运行良好,但在 Opera 或 IE 中不起作用。
一旦我添加了置于前面的代码,鼠标移出事件就永远不会在 Opera/IE 中应该触发的时候触发。
请参阅我在 JS Fiddle 上的示例,该示例在 Opera/IE 上已损坏。如果您注释掉 toFront()
行,它将在所有浏览器中按预期触发 mouseout 事件。
在该示例中 - 由于鼠标移开永远不会触发,因此发光仍然存在 - 每个形状都会产生多个发光。我可以通过在添加之前检查发光来解决此问题,但这并不能解决问题。
编辑 2: 所以我想出了 使用单个变量存储发光对象的解决方案 似乎可以解决问题。有趣的是,包含 div 上的 mouseout 事件实际上并没有在 Opera 中被调用(尚未检查 IE)。哇老兄,这么近:(
EDIT: After writing my question, it has occurred to me that the toFront()
code probably recreates the element in a different position in the DOM. When it removes the element first, it probably loses any events attached for IE and Opera, hence my problem. I will work on a delegated event alternative but still open to suggestions.
I have shapes in a Raphael paper that are suppose to glow when you hover over them. However, since these shapes are position directly next to each other, to make sure you see the glow all the way around I have to bring the current shape to the front.
This the current element is on top, so it's glow will appear over the top of adjacent shapes. My code works fine in Webkit and Firefox, but it doesn't work in Opera or IE.
Once I added in the bring to front code, the mouseout event never trigger when it should in Opera/IE.
Please see my example on JS Fiddle which is broken for Opera/IE. If you comment out the toFront()
line, it will trigger the mouseout event as expected in all browsers.
In that example - since the mouseout nevers get trigger, ergo the glow remains - multiple glows build up per shape. I can fix this by checking for the glow before adding it but this doesn't fix the problem.
EDIT 2: So I've come up with a solution that uses single variable to store the glow object which seems to fix the problem. Interestingly enough though, a mouseout event on the containing div doesn't actually get called in Opera (haven't checked IE). Awww man, so close :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这在 Opera 中适用于我,还没有在 IE 中尝试过,但它应该可以工作:
http://jsfiddle.net/76bjf/
This works for me in Opera, haven't tried in IE but it should work:
http://jsfiddle.net/76bjf/