将 JQuery Lightbox() 函数与 Datalist 中的 HTML 链接元素链接

发布于 2024-10-06 06:09:09 字数 739 浏览 0 评论 0原文

我正在 DataList 中实现此 JQuery Lightbox 插件:

如果链接位于 DataList 之外,我测试了此代码是否可以工作:

$('a[@rel*=lightbox]').lightBox();

但它似乎没有拾取 DataList 内具有“rel=lightbox”的链接。

所以我四处挖掘并尝试从这里吸取一些教训:

想出了这个,但似乎不起作用:

            $('a.imageActivator').live("click", function() {
                jQuery.lightBox();
            });

出了什么问题?

I'm implementing this JQuery Lightbox plugin inside a DataList:

I tested this code to work if the link is outside the DataList:

$('a[@rel*=lightbox]').lightBox();

But it does not seem to pick up the links inside the DataList which has "rel=lightbox".

So I went digigng around and try to take some lessons from here:

Came up with this but does not seem to work:

            $('a.imageActivator').live("click", function() {
                jQuery.lightBox();
            });

What went wrong?

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

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

发布评论

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

评论(2

三生一梦 2024-10-13 06:09:09

我认为您需要在点击函数中包含 return false;

I think you need to include a return false; in your click function.

感情废物 2024-10-13 06:09:09

我尝试了 JQuery Lightbox 和 JQuery Fancybox。

JQuery Lightbox (如上所述)似乎存在 lightBox() 无法绑定/链接到 Click 事件的问题。

JQuery Fancybox 提出了必须单击两次才能激活图像的问题。而且它也不显示第二张图像(但再次显示相同的第一张图像)。

所以最后,我打破了常规,使用了 Lightbox2

问题是 $ 与全局声明的 JQuery 的 $ 冲突。因此,在做了一些研究之后,这是我对此的建议。

按如下方式对脚本进行排序:

<script type="text/javascript" src="/scripts/prototype.js"></script>
<script type="text/javascript" src="/scripts/scriptaculous.js?load=effects,builder"></script>
<script type="text/javascript" src="/scripts/lightbox.js"></script>

<script type="text/javascript" src="/scripts/jquery-1.4.2.js"></script> 

JQuery 脚本必须具有“jQuery.noConflict();”作为第一行。页面上使用的任何 JQuery $ 符号都必须更改为“jQuery”。例如:

    <script type="text/javascript">
        jQuery.noConflict();

        jQuery(function() {
            jQuery('a.activator').live("click", function() {
                jQuery('#enquireOverlay').fadeIn('fast', function() {
                    jQuery('#box').animate({ 'top': '160px' }, 500);
                });
            });

            jQuery('#boxclose').click(function() {
                jQuery('#box').animate({ 'top': '-200px' }, 500, function() {
                    jQuery('#enquireOverlay').fadeOut('fast');
                });
            });
        });
    </script>   

这使我能够使用与 jQuery 脚本共存的 Lightbox。

I tried JQuery Lightbox and JQuery Fancybox.

JQuery Lightbox (as above) seem to present the issue that the lightBox() cannot be bound/linked to the Click event.

JQuery Fancybox presented the issue of having to click TWICE to activate the image. And it also doesn't show the 2nd image (but show the same 1st image again).

So in the end, I went against the norm and used Lightbox2 instead:

The issue with this is the $ conflicts with JQuery's $ which is declared globally. So here is my tip around this after doing some research.

Sequence the scripts as follow:

<script type="text/javascript" src="/scripts/prototype.js"></script>
<script type="text/javascript" src="/scripts/scriptaculous.js?load=effects,builder"></script>
<script type="text/javascript" src="/scripts/lightbox.js"></script>

<script type="text/javascript" src="/scripts/jquery-1.4.2.js"></script> 

JQuery script will have to have "jQuery.noConflict();" as the first line. Any JQuery $ sign used on the page will have to be changed to "jQuery". For Example:

    <script type="text/javascript">
        jQuery.noConflict();

        jQuery(function() {
            jQuery('a.activator').live("click", function() {
                jQuery('#enquireOverlay').fadeIn('fast', function() {
                    jQuery('#box').animate({ 'top': '160px' }, 500);
                });
            });

            jQuery('#boxclose').click(function() {
                jQuery('#box').animate({ 'top': '-200px' }, 500, function() {
                    jQuery('#enquireOverlay').fadeOut('fast');
                });
            });
        });
    </script>   

That was what allowed me to use a Lighbox that works which co-exists with jQuery scripts.

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