Why does fancybox require two clicks activate?

狂风中的少年 提交于 2019-12-29 08:22:17

问题


jQuery

  <script type="text/javascript">
    jQuery(document).ready(function () {
        jQuery("a.fancybox_videojs").click(function(e) {
            e.preventDefault();

            var url = jQuery(this).attr('title');
            var rel = jQuery(this).attr('rel');
            var img = jQuery(this).children('img').attr('src');

            jQuery(this).fancybox({
                'overlayOpacity' : <?php echo get_option('fancybox_overlayOpacity'); ?>,
                'overlayColor' : '<?php echo get_option('fancybox_overlayColor'); ?>',
                'hideOnContentClick' : false,
                'content': '<div><div class="video-js-box vim-css">' +
                              '<video id="example_video_1" class="video-js" width="650" height="370" controls="controls" preload="auto" poster="' + img + '">' +
                              [...omitted...]
                              '</video>' +
                              '</div></div>',
                'titleShow' : false,
                'onComplete': function () { 
                    jQuery("#fancybox-inner").css({ 'overflow': 'hidden' });
                    VideoJS.setupAllWhenReady();
                },
                'onClosed': function () { jQuery("#fancybox-inner").empty(); }
            });
        });
    });
  </script> 

HTML

<div class="content-wrap container_12">
  <div class="work_cat alpha">
    <a href="" id="##"></a>
  </div>
  <div class="work_col">
    <div class="work_cell" id="thumb_##">
      <a class="fancbox_videojs" href="" title="" rel=""><img src=""></a>
      <a class="fancbox_videojs" href="" title="" rel=""></a>
    </div>
  </div>
  <div class="work_col"></div>
  <div class="work_col omega"></div>
</div>

I have two problems here.

  1. It takes two clicks to bring up the fancybox.
  2. I want the link in .work_cat to also bring up the fancybox, but it has to get the variables from the coresponding .work_cell

I omitted part of the jQuery code so it would not be too long. If you need to see it, I will post it up


回答1:


fancybox works on click.

Try this instead (attach fancybox to all the places you want it):

  jQuery("a.fancybox_videojs").click(function(){return false;})
    .each(function(i,item) {
        var url = jQuery(this).attr('title');
        var rel = jQuery(this).attr('rel');
        var img = jQuery(this).children('img').attr('src');

        jQuery(this).fancybox({
            'overlayOpacity' : <?php echo get_option('fancybox_overlayOpacity'); ?>,
            'overlayColor' : '<?php echo get_option('fancybox_overlayColor'); ?>',
            'hideOnContentClick' : false,
            'content': '<div><div class="video-js-box vim-css">' +
                          '<video id="example_video_1" class="video-js" width="650" height="370" controls="controls" preload="auto" poster="' + img + '">' +
                          [...omitted...]
                          '</video>' +
                          '</div></div>',
            'titleShow' : false,
            'onComplete': function () { 
                jQuery("#fancybox-inner").css({ 'overflow': 'hidden' });
                VideoJS.setupAllWhenReady();
            },
            'onClosed': function () { jQuery("#fancybox-inner").empty(); }
        });
    });


来源:https://stackoverflow.com/questions/6510194/why-does-fancybox-require-two-clicks-activate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!