【发布时间】:2018-08-19 19:23:03
【问题描述】:
我正在从 CDN 加载 jQuery PrettyPhoto。我有这个 JS 可以从键盘启用帖子导航:
// Add keyboard navigation for the next & previous post buttons
$(document).keydown(function (e) {
var url = false;
if (e.which == 37) { // Left arrow key code
url = $('a.prev-post').attr('href'); // change to match the pagination link classes in your theme
} else if (e.which == 39) { // Right arrow key code
url = $('a.next-post').attr('href');
}
if (url) {
window.location = url;
}
});
我想添加一个布尔值,以防止在 PP 模式打开时执行此代码,但我不知道该怎么做。 PP中的相关代码是:
// Window/Keyboard events
$(window).unbind('resize.prettyphoto').bind('resize.prettyphoto',function(){ _center_overlay(); _resize_overlay(); });
if(pp_settings.keyboard_shortcuts) {
$(document).unbind('keydown.prettyphoto').bind('keydown.prettyphoto',function(e){
if(typeof $pp_pic_holder != 'undefined'){
if($pp_pic_holder.is(':visible')){
switch(e.keyCode){
case 37:
$.prettyPhoto.changePage('previous');
e.preventDefault();
break;
case 39:
$.prettyPhoto.changePage('next');
e.preventDefault();
break;
case 27:
if(!settings.modal)
$.prettyPhoto.close();
e.preventDefault();
break;
};
// return false;
};
};
});
};
我知道我可以在帖子导航上做这样的事情:
// Add keyboard navigation for the next & previous post buttons
var canUseArrows = true;
$(document).keydown(function (e) {
var url = false;
if (e.which == 37 && canUseArrows) { // Left arrow key code
url = $('a.prev-post').attr('href'); // change to match the pagination link classes in your theme
} else if (e.which == 39 && canUseArrows) { // Right arrow key code
url = $('a.next-post').attr('href');
}
if (url) {
window.location = url;
}
});
但我不确定如何挂钩 PP 函数。
感谢收看,
【问题讨论】:
标签: javascript jquery wordpress prettyphoto