javascript - jQuery 漂亮的照片插件不会在图库中显示缩略图

标签 javascript jquery html css prettyphoto

我正在使用 jquery 漂亮的照片插件作为我的图片库。但是当我打开一张照片时,它工作正常但不显示缩略图,而是显示其 css 中定义的默认背景:

我的结果: enter image description here

我想要的结果: enter image description here

我的 HTML:

<ul class="hover_thumb_wrap">
    <li class="hover_thumb_unit">
        <a rel="prettyPhoto[18]" class="imgwrap" title="Item Title" href="http://placehold.it/800x600" style="cursor: pointer;">
        <img width="50" height="50" alt="Item Thumbnail Alt" class="attachment-50x50" src="http://placehold.it/50x50">
        </a>
    </li>
    <li class="hover_thumb_unit">
        <a rel="prettyPhoto[18]" class="imgwrap" title="Item Title" href="http://placehold.it/400x500" style="cursor: pointer;">
        <img width="50" height="50" alt="Item Thumbnail Alt" class="attachment-50x50" src="http://placehold.it/50x50">
        </a>
    </li>

</ul>

我的Javascript:

jQuery("#item-wrap a[rel^='prettyPhoto']").prettyPhoto({
            animationSpeed: 'normal', /* fast/slow/normal */
            padding: 15, /* padding for each side of the picture */
            opacity: 0.7, /* Value betwee 0 and 1 */
            showTitle: false, /* true/false */
            allowresize: true, /* true/false */
            counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
            //theme: 'dark_square', /* light_rounded / dark_rounded / light_square / dark_square */
            hideflash: false, /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */
            modal: false, /* If set to true, only the close button will close the window */
            callback: function() {
                var url = location.href;
                var hashtag = (url.indexOf('#!prettyPhoto')) ? true : false;
                if (hashtag) location.hash = "!";
            } /* Called when prettyPhoto is closed */,
            social_tools : ''
      });

最佳答案

问题是 prettyPhoto 验证你的图像 url。 验证以 jpg|jpeg|png|gif 结尾的图像 url。 所以解决方案是:

1: 更改您的图片网址 http://placehold.it/800x600 => http://placehold.it/800x600.jpg

2:编辑文件:jquery.prettyPhoto.js(解压版)第763行:注释这段代码

if(!pp_images[i].match(/\b(jpg|jpeg|png|gif)\b/gi)){
                    classname = 'default';
                    img_src = '';
                }else{
                    classname = '';
                    img_src = pp_images[i];
                }

并替换为

classname = '';
img_src = pp_images[i];

完成!

关于javascript - jQuery 漂亮的照片插件不会在图库中显示缩略图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19857157/

相关文章:

javascript - 在页面顶部获取脚本,因此出现 $ not Define 之类的错误

javascript - Android 上的 RN 可访问性 - TalkBack 读取 View 的顺序

javascript - 调用 jquery 插件时是否应该使用 try-catch

javascript - 在页面上创建弹出窗口时,Home 和 End 键不起作用?

javascript - 在 html/jquery 中制作下拉列表,无需遵循任何教程

javascript - 搜索数组返回部分匹配

javascript - 在 event.preventDefault() 之后启用按钮默认值

jquery - 使用 .val() 将文本添加到段落

html - 在列表中添加小图像?

javascript - 如何调整我的 iframe