如何为prettyPhoto

时间:2019-07-02 06:08:36

标签: javascript jquery html css prettyphoto

首先,我在桌子上有这个看法: enter image description here

当我单击td时,它会打开PrettyPhoto Lightbox

在prettyPhoto上,默认的html触发器是:

<a href="images/fullscreen/2.jpg" rel="prettyPhoto" title="This is the description">
    <img src="images/thumbnails/t_2.jpg" width="60" height="60" alt="This is the title" />
</a>

但是我有这个html:

<a href="image.jpeg" data-rel="prettyPhoto" rel="prettyPhoto[pp_gal]" class="kt-user-card-v2">
    <div class="kt-user-card-v2__pic">
        <img src="http://wasapbro-2019.test/storage/msg/cupb1RUgcGLnUovQi7eBpxLIIRu37sPKcha1jjuI.jpeg" class="m-img-rounded kt-marginless" alt="photo">
    </div>
    <div class="kt-user-card-v2__details">
        <span class="kt-user-card-v2__name">test</span>
    </div>
</a>

在无法触发的地雷上

我该如何解决?

1 个答案:

答案 0 :(得分:0)

我不确定您是如何初始化PrettyPhoto的,但是我使用您的DOM结构设置了此快速演示,它似乎工作正常。需要注意的一件事是,由于PrettyPhoto依赖于.size(),因此您需要使用jQuery 2.x或更早版本。在jQuery 3.0+中不可用。

$(document).ready(function() {
    $("a[rel^='prettyPhoto']").prettyPhoto();
});
<!DOCTYPE html>
<html>

<head>
    <title>Pretty Photo</title>
    <script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
    <link rel="stylesheet" href="https://lib.arvancloud.com/ar/prettyPhoto/3.1.6/css/prettyPhoto.min.css" type="text/css" media="screen" charset="utf-8" />
    <script src="https://lib.arvancloud.com/ar/prettyPhoto/3.1.6/js/jquery.prettyPhoto.min.js" type="text/javascript" charset="utf-8"></script>
</head>

<body>
    <table>
        <tr>
            <td>
                <a href="https://live.staticflickr.com/8183/8079715772_f003d725d1_z.jpg" data-rel="prettyPhoto" rel="prettyPhoto[pp_gal]" class="kt-user-card-v2">
                    <div class="kt-user-card-v2__pic">
                        <img src="https://live.staticflickr.com/8183/8079715772_f003d725d1_z.jpg" class="m-img-rounded kt-marginless" alt="photo">
                    </div>
                    <div class="kt-user-card-v2__details">
                        <span class="kt-user-card-v2__name">test</span>
                    </div>
                </a>
            </td>
        </tr>
        <tr>
            <td>
                <a href="https://live.staticflickr.com/8512/8509212953_4cfefc8b9a_z.jpg" data-rel="prettyPhoto" rel="prettyPhoto[pp_gal]" class="kt-user-card-v2">
                    <div class="kt-user-card-v2__pic">
                        <img src="https://live.staticflickr.com/8512/8509212953_4cfefc8b9a_z.jpg" class="m-img-rounded kt-marginless" alt="photo">
                    </div>
                    <div class="kt-user-card-v2__details">
                        <span class="kt-user-card-v2__name">test</span>
                    </div>
                </a>
            </td>
        </tr>
    </table>
</body>

</html>