PhotoSwipe:如何将函数绑定到图像点击事件
PhotoSwipe: how to bind a function to the image tap event?
我确实用幻灯片放映功能扩展了PhotoSwipe,请参阅此示例。如果单击右上角的"播放"按钮,则幻灯片放映开始,然后单击右上角落的暂停按钮停止幻灯片放映。这在PC上运行良好。
它也适用于我的iPad,但单击"暂停"按钮会产生副作用:图像会被放大。我不知道这是什么原因。知道吗?
Start/Stop函数是在函数playpause()中执行的。为了消除这种副作用,我喜欢使用图像上的单次点击事件来执行我的playpause()函数。
所以我的问题是:如何将我的playpause()函数绑定到图像上的点击/点击事件?
这是我使用的代码:
/** HTML **/
<div class="pswp__top-bar">
<div class="pswp__counter"></div>
<!-- Play/Pause button -->
<a href="javascript:playpause()" id="link--play"><img src="res/play.png" width="30" height="30" id="$playpause" alt="Speel/Stop (spatie balk)" title="Speel/Stop (spatie balk)"></a>
<button class="pswp__button pswp__button--close" title="Close (Esc)"></button>
/** JS **/
function slideShowTimer() {
if ((stopAfterLastSlide)&&((slide_index == items.length-1))) {
document.images['$playpause'].src = play_img.src;
clearTimeout(slideShowTimerID);
playing= !playing;
pswp.close();
}
else {
slideShowTimerID = setTimeout("slideShowTimer()",viewtime);
pswp.next();
}
};
function playpause() {
playing= !playing;
if (!playing) {
document.images['$playpause'].src = play_img.src;
clearTimeout(slideShowTimerID);
} else {
document.images['$playpause'].src = pause_img.src;
slideShowTimer();
}
};
pswp = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options);
pswp.listen('destroy', function() {
if (playing) {
playing = false;
document.images['$playpause'].src = play_img.src;
clearTimeout(slideShowTimerID);
}
});
pswp.init();
/** CSS **/
#link--play {
position: absolute;
right: 132px;
padding: 6px;
z-index: 9999;
}
您没有显示任何代码,这使得很难提供适当的帮助。
只是在黑暗中拍摄:使用event.preventDefault();
我做了这个实现,它运行得很好:https://photoswipe.uservoice.com/forums/275302-feature-requests-ideas/suggestions/6964114-autoplay
我确实用下一个代码将我的playpause()函数绑定到了图像上的点击/点击事件:
ui.onGlobalTap = function(e) {
e = e || window.event;
var target = e.target || e.srcElement;
if ((framework.hasClass(target, 'pswp__img')) && !PC) {
if(!_controlsVisible) {
ui.showControls();
setTimeout(function() {
ui.hideControls();
}, 2000);
}
playpause();
return;
}
要查看其工作情况,请访问:http://andrewolff.jalbum.net/Reestdal_PS/#&gid=1&pid=6,但单击图像以开始/停止幻灯片放映仅在iPad等移动设备上有效,在PC上,您可以使用空格键开始/停止放映幻灯片。
如果你点击右上角的播放/暂停按钮,我没有解决你在iPad上看到的副作用。
相关文章:
- 无法在java脚本中调用图像的点击事件函数
- 如何使用更新图像源以响应新闻事件
- 正在捕获动态更改其源的图像的加载事件
- 如何在asp:linkButton上显示鼠标悬停事件上的图像
- 在onmouseover事件中更改图像,并为每个事件设置中断/间隔
- 如何通过一个onclick事件更改两个单独的图像
- 如何使用onclick事件点击一个图像,并让它更改同一网页上的另一个图像
- 使用事件侦听器更改图像
- HTML5/JavaScript图像点击事件
- 使用单击事件如何更改图像
- 获取图像宽度的最早事件
- 使用完整日历在网站上获取并显示来自Google日历事件的附加图像
- 如何使用 OnClick 事件更改结构 JS 的覆盖图像
- 单击图像滑块计时器的事件
- 如何在鼠标移动事件时更改图像的窗口中心和宽度
- iFrame.load事件未等待预加载图像完成
- 创建随机图像交换并禁止鼠标悬停事件
- 在弹出图像事件上绑定和取消绑定鼠标滚轮 - JQuery
- 在HTML和JavaScript中的图像事件
- Kinect 中的可拖动图像事件