【问题标题】:PrettyPhoto not work with livequeryPrettyPhoto 不适用于 livequery
【发布时间】:2011-01-23 09:24:14
【问题描述】:

谁能解释如何将 PrettyPhoto 与 livequery 一起使用?

  $(document).ready(function()
  {
    $(".gallery a[rel^='prettyPhoto']").livequery(
    function()
    {
      $(this).prettyPhoto({theme:'facebook'});
    });
  });

代码是正确的,但我认为 livequery 不支持 PrettyPhoto。有人可以确认吗?

【问题讨论】:

  • 当你尝试时会发生什么?

标签: prettyphoto livequery


【解决方案1】:

你说的是 jQuery 吗?如果是这样,我已经得到了这个工作:

$("a[rel=prettyPhoto]").live("click",function() {
    $.prettyPhoto.open($(this).attr("href"),"","");
    return false;
});

如果你想加入一些主题或你可以做的事情:

$.fn.prettyPhoto({'theme': 'light_rounded'});
$("a[rel=prettyPhoto]").live("click",function() {
    $.prettyPhoto.open($(this).attr("href"),"","");
    return false;
});

【讨论】:

  • 不错,但记得先实例化 prettyPhoto,$("a[rel^='prettyPhoto']").prettyPhoto();
  • 感谢大卫(感谢@EricHerlitz 提供的额外数据)。非常适合我。
  • 请记住,现代 jQuery .live() 不再起作用,因此您必须使用 .on() 做类似的事情。
【解决方案2】:
$.fn.prettyPhoto({
    animation_speed: 'fast', /* fast/slow/normal */
    slideshow: 5000, /* false OR interval time in ms */
    theme: 'facebook' /* light_rounded / dark_rounded / light_square / dark_square / facebook /pp_default*/
});

$.prettyPhoto.open('xzs.html?iframe=true&width=100%&height=100%','Title','DESC');

User
<a style="color: #F99;text-decoration:inherit;" href="javascript:;" rel="prettyPhoto[iframes]" name="xzs.html?iframe=true&width=100%&height=100%" title="test">test</a>

$("a[rel^='prettyPhoto']").livequery(function(){
    var url = $(this).attr(name);
    $.prettyPhoto.open(url,'Title','DESC');
});

【讨论】:

    【解决方案3】:

    发生的情况是 prrettyPhoto 为每张照片实例化一个画廊,而不是使用 rel 属性上的正则表达式来构建集合。您需要做的是在 all a[rel^='prettyPhoto'] 上重新运行初始化,每当您在 DOM 中获得新的初始化。这是由于 prettyPhoto 使用全局 matchedObjects var 设置的方式。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-02
      • 2017-01-14
      • 2016-05-22
      • 2012-05-16
      相关资源
      最近更新 更多