页面加载自动打开后无法关闭 fancybox

Can't close fancybox after automatic open on page load

我对在页面加载时自动打开的 fancybox 有疑问。单击关闭按钮后,fancybox 再次打开。

你能帮帮我吗?

<script>
 jQuery(function($){
  $(".popup-wrapper").fancybox({
  'padding': '0',
  'max-width': '50%',
  'max-height': '50%',
  'autoSize': false,
  'transitionIn': 'fade',
  'transitionOut': 'fade',
  });

 $(".popup-wrapper").trigger('click');
});
</script>

css:

.popup-wrapper {
 display: none;
 width: 50%;
 height: auto;
   img {
    width: 80%;
   height: auto;
 }
}

php & html

<?php $args = array('post_type' => 'popup', 'showposts' => 5,); 
$the_query = new WP_Query( $args ); ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post();
$meta = get_post_meta( $post->ID, 'popup_details', true ); ?>

<?php if (is_array($meta) && $meta['displayPopup'] === '1') { ?>
<div class="popup-wrapper col-12 col-xl-12">
    <?php the_post_thumbnail(); ?>
</div><!-- .popup-wrapper -->
<?php }; 
endwhile;

wp_reset_postdata(); ?>

更新 仅当我单击关闭按钮时才会出现问题。当我按下 ESC 按钮或单击黑色背景时,框会正常关闭。

我通过在我的代码中添加 preventDefault 解决了这个问题,现在它可以工作了。希望这对将来的人有所帮助。

jQuery(function($){
 $(".popup-wrapper").fancybox({
  'padding': '0',
  'autoSize': true,
  'transitionIn': 'fade',
  'transitionOut': 'fade',
 });

 $(".popup-wrapper").trigger('click');

 $(document).find('.fancybox-close-small').on('click', function(e) {
   e.preventDefault();
      self.close(e);
 });
});