I have this problem on woocommerce site, that when user on mobile click close button on image lightbox link in background is also clicked. In my example close button overlap basket icon. So when you close image, basket is opened. close button is over basket icon I am using wocommerce 3.0 lightbox
link to page with problem: https://nakit-ure.si/rocne-ure/rocna-ura-just-watch-jw20004-008/ (open in mobile view click on image and then try closing it)
I tried using jquery:
1. first add class on basket when image is opened
CSS
{
.pointer-disable{pointer-events:none}
}
THIS JQUERY WORK
(function($) {
$(document).ready(function(){
$('.wp-post-image').click(function(){
$('.nav-right').addClass('pointer-disable');
});
})
})(jQuery);
NOW I need to disable class when image is closed.
remove class when image is closed.
THIS JQUERY DONT work
(function($) {
$(document).ready(function(){
$('.pswp__button--close').click(function(){
$('.nav-right').removeClass('pointer-disable');
});
})
})(jQuery);
4
Answers
Try to use $(‘className’).on(‘click’) instead of .click() events because the former can use less memory and work for dynamically added elements.
You can do like this:
You just have to strop the event bubbling:
The problem solved in my case. If I understand correctly, the reason was in event bubbling and capturing. Woocommerce lightbox is a div layer with heigh z-index. But touch event on this layer works also for lower layer. It was need to stop event handling. I used for this ontouchstart = “return false;”, which was added to woocommerce/single-product/photoswipe.php.