colorbox 不支持 Ajax

发布于 2024-12-03 13:28:09 字数 1606 浏览 0 评论 0原文

我正在尝试从 ajax 调用动态加载的内容中打开 colorbox。单击“下一步”时,它会在页面上加载另一个块,单击该块时,应打开颜色框覆盖。

但是对于第一个项目颜色框打开,然后我无法将颜色框与链接绑定。

请看,我用于绑定 colorbox 的 javascript 代码是:

$(document).ready(function() {
    $('#recommended-app-wrapper .app_download_link').each(function() {
        $(this).colorbox({
            href: $(this).attr('href'),
            iframe: false,
            onComplete: function() {
                //  Tooltip
                $('#modal a.link_tooltip').each(function() {
                    $(this).click(function() {
                        return false;
                    });
                    var content = $(this).next('.hidden').html();
                    $(this).aToolTip({   
                        tipContent: content,
                        fixed: true,
                        clickIt: false,
                        xOffset: -180,
                        yOffset: 30
                    });
                });
                //  Clear-Default
                $('#modal input.clear-default').clearDefault();
            }
        });
    });
});    

调用内容页面的 JSP 代码是

<dsp:a page="/fragments/product_app_download.jsp" iclass="custom custom-blue-smapp_download_link get-app">
    <dsp:param name="id" param="element.id"/>
    Get app
</dsp:a>

请参阅主页,从中进行 ajax 调用,并加载用户可以从中单击并打开 colorbox 的块。我已经截取了代码的屏幕截图。

http://i.imgur.com/Z0BVQ.png

我认为,问题是,我将颜色框绑定在document.ready 仅被调用一次,然后单击“下一个”后,它不会将我的下一个项目绑定到颜色框。

请帮忙。

谢谢

I am trying to open colorbox from dynamically loaded contents from ajax calls. On click of next it loads another block on the page and on clicking on that block, colorbox overlay should be opened.

But for the first item colorbox is opened, then after i am not able to bind colorbox with the link.

Please see, my javascript code which is used to bind colorbox is:

$(document).ready(function() {
    $('#recommended-app-wrapper .app_download_link').each(function() {
        $(this).colorbox({
            href: $(this).attr('href'),
            iframe: false,
            onComplete: function() {
                //  Tooltip
                $('#modal a.link_tooltip').each(function() {
                    $(this).click(function() {
                        return false;
                    });
                    var content = $(this).next('.hidden').html();
                    $(this).aToolTip({   
                        tipContent: content,
                        fixed: true,
                        clickIt: false,
                        xOffset: -180,
                        yOffset: 30
                    });
                });
                //  Clear-Default
                $('#modal input.clear-default').clearDefault();
            }
        });
    });
});    

JSP code which calls the content page is

<dsp:a page="/fragments/product_app_download.jsp" iclass="custom custom-blue-smapp_download_link get-app">
    <dsp:param name="id" param="element.id"/>
    Get app
</dsp:a>

Please see the main page, from where the ajax call is being made and it loads the block from which user can click and open the colorbox. I have taken the screenshot of the code.

http://i.imgur.com/Z0BVQ.png

I think, the issue is , i am binding the colorbox on document.ready which is called only one time, then after on clicking of next it doesnt bind my next item to colorbox.

Kindly help.

thank you

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

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

发布评论

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

评论(2

厌味 2024-12-10 13:28:09

您可以使用 jquery .live() 函数将事件绑定到尚未创建的元素它。我想这就是你可能需要的。

You can use the jquery .live() function to bind events to elements that haven't even been created it. I think this is what you might need.

不必你懂 2024-12-10 13:28:09

像这样思考你的问题:在页面加载时,最初 DOM 已准备好,并且为选择器初始化了 colorbox AJAX 调用页面的一个新部分,其中包含一些位于 colorbox 选择器列表中的 DOM 元素,但没有被注意到,因为它在 JavaScript 读取选择器后加载到页面中。

现在尝试这个,因为它会监视所有现有的和新的“.app_download_link”的“#recommished-app-wrapper”:

$("#recommended-app-wrapper").delegate(".app_download_link", "click", function (event) {
                    event.preventDefault();
                    $.colorbox({href: $(this).attr("href"),
                            transition: "fade",
                            innerHeight: '515px',
                            innerWidth: '579px',
                            overlayClose: true,
                            iframe: true,
                            opacity: 0.3},
                            onComplete: function() {
                                $('#modal a.link_tooltip').each(function(event) {
                                    if(event === "click")
                                        return false;
                                    var content = $(this).next('.hidden').html();
                                    $(this).aToolTip({   
                                       tipContent: content,
                                       fixed: true,
                                       clickIt: false,
                                       xOffset: -180,
                                       yOffset: 30
                                    });
                                });
                                //  Clear-Default
                                $('#modal input.clear-default').clearDefault();
                          });
                });

这种方式不是等待让插件监视事件,而是使用 .delegate() 监视事件,并且即时执行颜色框...

onComplete 函数可能不完全是您所需要的,但您明白了。

Think of your problem like this: On page load initially the DOM is ready, and colorbox is initilized for the selector AJAX calls a new piece of the page with some DOM element that is in the colorbox selector list, but isn't noticed because it loaded into the page after the selector was read by the javascript.

now try this, as it watches "#recommended-app-wrapper" for all, existing and new ".app_download_link":

$("#recommended-app-wrapper").delegate(".app_download_link", "click", function (event) {
                    event.preventDefault();
                    $.colorbox({href: $(this).attr("href"),
                            transition: "fade",
                            innerHeight: '515px',
                            innerWidth: '579px',
                            overlayClose: true,
                            iframe: true,
                            opacity: 0.3},
                            onComplete: function() {
                                $('#modal a.link_tooltip').each(function(event) {
                                    if(event === "click")
                                        return false;
                                    var content = $(this).next('.hidden').html();
                                    $(this).aToolTip({   
                                       tipContent: content,
                                       fixed: true,
                                       clickIt: false,
                                       xOffset: -180,
                                       yOffset: 30
                                    });
                                });
                                //  Clear-Default
                                $('#modal input.clear-default').clearDefault();
                          });
                });

This way instead of waiting for letting the plugin watch for the event, watch the event with .delegate(), and execute the colorbox on the fly...

The onComplete function may not be exactly what you need, but you get the idea.

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