如何根据元素的位置定位悬停 div
请参阅以下jsfiddle: http://jsfiddle.net/bhellman1/Na3hd/11/
现在,当您将鼠标移到该框上时,所有项目的悬停框都会出现在同一位置。
我想做的是根据您将鼠标悬停在哪个 #box.corner 上来定位悬停框。如果 #box.corner 位于框的左侧,我希望悬停框位于左侧、框外、居中于角落......如果您将鼠标悬停在底部的 #box.corner 上是的,我希望悬停框显示在右下角,以角落为中心。
关于如何实现这一目标有什么想法吗?
谢谢
Please see the following jsfiddle: http://jsfiddle.net/bhellman1/Na3hd/11/
Right now when you move over the box, the hoverbox appears in the same place for all items.
What I would like to do is position the hover box based on which #box.corner you are moused over. If the #box.corner is to the left of the box, I'd like the hover box in the left, outside the box, centered to the corner.... If you mouse over a #box.corner that's in the bottom right, I'd like the hover box to show at the bottom right, centered to the corner.
Any ideas on how to accomplish this?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我正确地阅读了您的问题,这应该是您正在寻找的内容: http://jsfiddle.net/Na3hd/17 /
如您所见,我移动了一些 css,以匹配不同元素更多的共同点,以便可以轻松地重用代码并将其分配给其他元素。我将悬停框的定义移至 mouseenter 函数中,以便在每个 mouseenter 上创建一个新的
div
,这样在设置位置时就不会导致复杂化。希望这有帮助!
编辑
这是一种更动态的方法:http://jsfiddle.net/Na3hd/22/
另外,我刚刚意识到你想让这些物品出现在盒子外面。
If I read your question correctly, this should be what youre looking for: http://jsfiddle.net/Na3hd/17/
As you can see i moved around some of the css to match what different elements have in common more, so that the code can easily be reused and assigned to other elements. I moved the defining of the hoverbox into the mouseenter function, so that a new
div
gets created on each mouseenter, which will then not result in complication when setting the positions.Hope this helps!
EDIT
Here a more dynamic approach: http://jsfiddle.net/Na3hd/22/
Also, i just realized you wanted to have these items show up outside of the boxes.