gpt4 book ai didi

javascript - PhotoSwipe 使用图像打开图库

转载 作者:行者123 更新时间:2023-12-02 18:54:48 26 4
gpt4 key购买 nike

我正在寻找一个解决方案,也可以使用 a 打开 PhotoSwipe 库图片链接。这样就有了一个带有图库图标的 IMG。我想要如果用户单击它即可打开图库。

有人知道我该如何处理吗?

我发现了这一点。但这是在加载图库时打开的。

<script type="text/javascript">
(function(window, PhotoSwipe){

document.addEventListener('DOMContentLoaded', function(){

var
options = {
preventHide: true
},
instance = PhotoSwipe.attach( window.document.querySelectorAll('#Gallery a'), options );

instance.show(0);

}, false);


}(window, window.Code.PhotoSwipe));

</script>

最好的调整

最佳答案

我刚刚开始使用 photoSwipe,所以我不确定这是否有效,但在我看来,您只需调用 instance.show(0)在点击事件上。

假设我在页面上有这个元素:<a id="launch-gallery" href="#">Click to launch gallery</a>我可以添加此 jQuery 单击事件来启动图库:

$('#launch-gallery').click(function(evt){
evt.preventDefault(); // prevent regular click action
instance.show(0); // Make sure 'instance' variable is available to this function
});

如果您不使用 jQuery,您可以在 native JavaScript 中执行相同的操作(但更详细一些)。

我希望这会有所帮助。

关于javascript - PhotoSwipe 使用图像打开图库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15496776/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com