livequery不与群组合作 [英] livequery not working with groups

查看:101
本文介绍了livequery不与群组合作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery的一些很好的插件来使用基于AJAX的站点。现在我遇到了一个问题,我想使用livequery来指定我的slimbox。问题是,它没有按照linkFiler函数中的说明获取我的组。

I am using some nice plugins from jQuery for using AJAX based sites. Now I came to the problem that I would like to use livequery for specifying my slimbox. The problem is, that it doesn't get my groups as stated in the linkFiler function.

$(document).ready(function () 
{
    $('a[rel^="lightbox"]').livequery(function()
    {
        $(this).slimbox(null, function(el) // link mapper
        {
            return [el.href, el.title + '<br/><a href=\"' + el.href + '\">Download</a>'];
        }
        , function(el) // links filter
        {
            return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
        });
    });
});

出了什么问题?在我的网页(传记)中,只有当我刷新该网站上的网页时,slimbox才有效,但不会在点击我的页面。这些团体不在网站的唱片目录部分工作。

What's going wrong? In one of my pages (Biography), the slimbox only works when I refresh the page on that site, but not when clicking through my pages. The groups aren't working in the Discography section of the site.

部分生物和唱片目录如下:

Parts of the bio and discography pictures are as follows:

<a href="albumCover.jpg" rel="lightbox-disco"><img src="albumCover_thumb.jpg" alt=""></a>

<a rel="lightbox" href="bandPic.png"><img style="float:right;margin-left:1em;" src="bandPic_thumb.png" alt=""></a>

提前致谢!

更新

我在slimbox代码中发现了我的问题,因为它使用这个来它的链接。因此,每次触发livequery时,都会被覆盖,并且实际上应该包含完整选择器。也许我可以通过这样说来解决这个问题:

I found my problem in the slimbox code, because it uses the this to be its links. So everytime livequery is fired, the this is overwritten and should actually contain the full selector. Maybe I can solve this by just saying:

$('a[rel^="lightbox"]').livequery(function()
{
    $('a[rel^="lightbox"]').slimbox(null, function(el) // link mapper
...

但这样做会让livequery在很多时候对着slimbox发火,这不是通缉行为。有没有更好的方法为了让它不经常火?

But doing that would make livequery fire a lot of times towards slimbox, which is not wanted behaviour. Is there a nicer way to make it not fire so often?

UPDATE2

至于其他传记页面中的问题。有关删除图像的livequery更新,但是在添加图像时所有其他网站都已正确完成...多么奇怪......

As for the other questio in the biography pages. livequery updates on removing the image, but all the other sites are done properly on adding the images... How strange...

推荐答案

我实际上找到了解决方案,但它很奇怪。如果有人读到这个并且可以向我解释这一点,那就太好了。不知何故,livequery在我的代码中对空<$ c有所不同$ c>< head> 标签和已填充的。所以,当我的子页面中有< style> 标签时(例如BIO) Ø r DISCO),即使它是空的,实时查询也可以。如果我有一个空的< head> 标记,则实时查询仅适用于离开页面。这很奇怪。现在我刚刚创建了一个空的< style> 标签,每个页面都运行正常。

I actually found the solution, but it is rather strange. If someone reads this and can explain this to me, it would be nice. Somehow, livequery makes a difference in my code between empty <head> tags and filled ones. So, when I have a <style> tag inside my subpage (such as BIO or DISCO), even if it's empty, the livequery works. If I have an empty <head> tag, the livequery only works on leaving the page. Which was strange. Now I just created an empty <style> tag and every page works fine.

至于群组问题,我的livequery有点不同,所以livequery不再被调用了。在我的HTML中,我确信每个子页面中始终存在< div class =content> 。所以我可以做一个实时查询,例如:

As for the groups problem, I did my livequery a bit different, so the livequery isn't called as much anymore. In my HTML, I'm sure that there is always a <div class="content"> in every subpage. So I could do a livequery such as:

$('.content').livequery(function()
{
    $('a[rel^="lightbox"]').slimbox(null, function(el) // link mapper
...

slimbox的问题在于它可以将完整选择器作为其范围。因此将slimbox更改为不同的选择器将禁用旧选择器。
在其代码中,它执行以下操作:

The problem with slimbox, is that it can just take the complete selector as its scope. So changing slimbox to a different selector, will disable the old one. In its code, it does something like this:

var links = this; // where this is the $(selector)

这篇关于livequery不与群组合作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆