【问题标题】:Image is not opening in light box using ajax图像未使用 ajax 在灯箱中打开
【发布时间】:2015-11-02 12:09:41
【问题描述】:

我正在使用漂亮的照片库。我必须在灯箱中打开缩略图,但是当我单击缩略图时,它会在新窗口而不是灯箱中打开。

图片正在使用从文件加载:

var article  = "";
$.each(data, function( index, value ) {
    article +="<article class='entry isotope-item "+value.pcat_slug+"'><a href='images/portfolio/"+value.pcat_slug+"/"+value.pimg_name+"' rel='prettyPhoto[pp_gal]' data-rel='prettyPhoto'><img class='img-responsive' data-original='images/portfolio/"+value.pcat_slug+"/"+value.pimg_name+"' alt='"+value.pcat_name+"' title='"+value.pcat_name+"' src='images/portfolio/"+value.pcat_slug+"/"+value.pimg_name+"' /><span class='magnifier'></span></a></article>";
    //li +="<li class='"+value.cat_slug+"'><img src='images/portfolio/logo/"+value.pcat_slug+"/"+value.pimg_name+"'/></li>";
});

$(".portfolio").empty();
$(".portfolio").append(article);
$(".portfolio").append("<div class='clear'></div>");

从 ajax 加载后,图像将显示在此 div 中:

<div class="portfolio"></div>

我正在使用以下代码打开弹出窗口:

/*prettyPhoto*/ jQuery(document).ready(function(){
    jQuery('a[data-gal]').each(function() { jQuery(this).attr('rel', jQuery(this).data('gal'));}); jQuery("a[data-rel^='prettyPhoto']").prettyPhoto({animationSpeed:'slow',theme:'light_square',slideshow:false,overlay_gallery: false,social_tools:false,deeplinking:false});
});

【问题讨论】:

  • 问题在于,在文档准备就绪时,prettyPhoto 部分已经加载,所以您应该在文档准备就绪时首先生成.portfolio,然后运行 ​​prettyPhoto

标签: json ajax javascript jquery ajax


【解决方案1】:

您应该使用 window.load 而不是 document.ready。请看下面的代码。

jQuery(window).load(function(){
jQuery('a[data-gal]').each(function() { jQuery(this).attr('rel', jQuery(this).data('gal'));});
jQuery("a[data-rel^='prettyPhoto']").prettyPhoto({animationSpeed:'slow',theme:'light_square',slideshow:false,overlay_gallery: false,social_tools:false,deeplinking:false});
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-27
    • 1970-01-01
    • 2023-03-26
    • 2013-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多