如果 html 元素位于 div 的溢出区域且溢出属性设置为隐藏,如何检查该 html 元素是否可见?

发布于 2024-09-16 01:03:27 字数 561 浏览 2 评论 0原文

我有一组 LI 元素,其溢出属性设置为隐藏
jCarouselLite 插件。我想做的事 是滚动 jCarouselLite'd 元素以便滚动到 我想要 LI 元素,因为我已将其配置为 仅显示 3 个元素。 查看插件生成的 html 代码,我可以看到:

<ul ..>
    <li ..style="..overflow:hidden">1</li>
    <li ..style="..overflow:hidden">2</li>
    <li ..style="..overflow:hidden">3</li>
    <li ..style="..overflow:hidden">4</li>
</ul>

因此,我有插件显示的前 3 个 LI 元素,但没有最后一个。我想做的是滚动以便显示第四个 LI 元素,或者如果我设法检查最后一个 LI 是否在溢出区域内,我可以自己执行此操作,这样我就可以看看是否有必要滚动为了显示或不显示它。

希望我不会让事情变得混乱而难以理解。

I have a set of LI elements with overflow propety set to hidden by the
jCarouselLite plugin. What I would like to do
is to scroll the jCarouselLite'd element in order to scroll to the
LI element I want, since I have it configured to
show only 3 elements.
Looking at the html code generated by the plugin, I can see:

<ul ..>
    <li ..style="..overflow:hidden">1</li>
    <li ..style="..overflow:hidden">2</li>
    <li ..style="..overflow:hidden">3</li>
    <li ..style="..overflow:hidden">4</li>
</ul>

So, I have the first 3 LI elements shown by the plugin, but not the last one. What I would like to do is to scroll so that the 4th LI element is shown, or I can do that by myself if I manage to check if that last LI is within the overflow area, so I can see if it's necessary to scroll for it in order to show it or not.

Hope I'm not getting things confused to understand.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冷清清 2024-09-23 01:03:27

如果我理解正确的话,您想检查该组中的最后一个 li 是否具有样式溢出:隐藏。

您可以使用一个简单的选择器来完成此操作。

$(document).ready(function(){

  tester = $('li').last().css('overflow');
  alert (tester);

});​

这会将最后一个li的溢出样式设置为变量“tester”,并且当它发送警报框时,它将警告当前溢出状态。因此,如果溢出设置为隐藏,则会显示“隐藏”,如果溢出设置为滚动,则会显示“滚动”。

抱歉,如果我没有正确理解或回答您的问题。

If I understand you correctly, you want to check if the last li in that group has the style overflow: hidden.

You can do this with a simple selector.

$(document).ready(function(){

  tester = $('li').last().css('overflow');
  alert (tester);

});​

That will set the last li's overflow style to the variable "tester", and when it sends the alert box it will alert the current state of overflow. So if overflow is set to hidden, it will say "hidden", if overflow is set to scroll it will say "scroll".

Sorry if I didn't understand properly or answer your question.

盗心人 2024-09-23 01:03:27

我找不到原始问题的答案,但对于任何 jCarouselLite 插件用户,为了使 carouselLite 滚动到特定项目,我所做的就是修改私有方法 go< 的声明/strong> 插件以便将其公开,如下所示:

.. code ..
go = $.fn.jCarouselLite.go = function go(to) {
        if(!running) {
    .. code ..
}
.. code ..

我确信这不是最好的,更重要的是,更安全的解决方案,但目前它对我有用。只需调用

$().jCarouselLite.go(position);

我的脚本,将位置视为从 0 开始的数字(carouselLite 上的第一个位置)。

I couldn't find an answer for my original question, but as for any jCarouselLite plugin users, what I did in order to make the carouselLite scroll to a particular item, was to modify just the declaration of the private method go of the plugin in order to make it public, as follows:

.. code ..
go = $.fn.jCarouselLite.go = function go(to) {
        if(!running) {
    .. code ..
}
.. code ..

I'm sure it's not the best, and more importantly, safer solution, but for now it works for me. Just have to call

$().jCarouselLite.go(position);

on my script, considering position as a number starting from 0 (the first position on the carouselLite).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文