问题
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.
- It takes two clicks to bring up the fancybox.
- 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