html代码:

<a id="image1" href="images/1.jpg" class="swipebox" title="My Caption">
    <img src="images/1mini.jpg" alt="image" />
</a>


当用户输入以'#1'结尾的链接时触发pugin的Js代码

<script type="text/javascript">
    $(document).ready(function(){
        if(window.location.hash == "#1") {
            $( '#image1' ).swipebox();
        }
    });
</script>


我发现js代码

$( '#image1' ).swipebox();


仅在单击图像时有效。但是我需要在页面加载期间将其弹出。

最佳答案

打开页面加载时的swipebox;您能否尝试使用以下代码:

<script type="text/javascript">
    $(document).ready(function(){
        if(window.location.hash == "#1") {
            $( '#image1' ).swipebox();
            $( '#image1' ).click();//click the image programmatically
        }
    });
</script>

关于javascript - 使用包含哈希标签的链接在加载时触发插件swipebox,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42017324/

10-10 21:43