如何使用 jQuery 来确定 div 何时不在右侧视图中?
我有一个 div,当它聚焦时会显示在控件附近。最初,div 位于控件的左侧,生活很简单。一个简单的 if left < 0 { 左 = 0; }
会将 div 保留在屏幕上。现在 div 需要位于右侧,但我无法找出类似的代码。此外,代码不仅需要确定它是否在屏幕右侧,还需要确定它是否超出了(可能的)可滚动包含 div 的可见性。我怎样才能做到这一点?假设可以使用 $('.PanelScroll')
找到可滚动的 div(如果适用),我们可以调用需要放置的 div elem
。
I have a div that displays near a control when it's focused on. Initially, the div was on the left of the control, and life was easy. A simple if left < 0 { left = 0; }
would keep the div on the screen. Now the div needs to be on the right, and I can't figure out a similar bit of code. Also, the code needs to determine not only if it's off-screen to the right, but also if it's past the visibility of a (possible) scrollable containing div. How can I accomplish this? Assume the scrollable div, if applicable, can be found with $('.PanelScroll')
and we can call the div needing placement elem
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我一直在寻找的更简单的解决方案:
This is more of the simple solution I was looking for: