javascript 使用 JQuery 在 Fancybox 中显示隐藏的 div 不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5137771/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 16:06:09  来源:igfitidea点击:

Show hidden div in Fancybox using JQuery not working

javascriptjqueryhtmlfancybox

提问by Panama Hyman

I've been trying to get this code to work. I have a hidden div that shows a flash video using the object/embed method.

我一直在努力让这段代码发挥作用。我有一个隐藏的 div,它使用对象/嵌入方法显示 Flash 视频。

This is the js code I'm using.

这是我正在使用的js代码。

jQuery(document).ready(function(){  

    jQuery("a[id^='scrshot_']").fancybox(       
    {
    'autoDimensions'    : false,
    'width'                 : 640,
    'height'                : 360       
    });
    return false;});

I'm using this method I found on this site http://www.jdmweb.com/resources/fancy_videosand pretty easy to implement. I use dynamically created ID tags. BUT for some reason fancybox will open but the div inside stays hidden. When I use firebug to look at it, it shows the flash object inside but it still has the display:none attribute attached to it. How do you get it to show the contents inside that div and not the whole div? If the div is showing and use the link, fancybox open with the player fine. Obviously that wont work because I don't want the video to show until it launches in fancybox.

我正在使用我在这个网站http://www.jdmweb.com/resources/fancy_videos上找到的这种方法,并且很容易实现。我使用动态创建的 ID 标签。但是由于某种原因,fancybox 会打开,但里面的 div 保持隐藏。当我使用 firebug 查看它时,它显示了内部的 flash 对象,但它仍然附加了 display:none 属性。你如何让它显示该 div 中的内容而不是整个 div?如果 div 显示并使用链接,fancybox 用播放器打开就好了。显然这行不通,因为我不希望视频在fancybox 中启动之前显示。

Example of my html code.

我的 html 代码示例。

 <a class='scrshot' id='scrshot_1' href='#showvid_1'>Click Here</a>
<div class='showvid' id='showvid_1'>my embedded code here</div>

回答by silentmouth

Instead of hiding the div, make it visible but wrap it inside another div that is hidden.

与其隐藏 div,不如让它可见,但将它包裹在另一个隐藏的 div 中。

(I don't know why fancybox doesn't toggle the visibility, rather annoying.)

(我不知道为什么fancybox不切换可见性,很烦人。)

回答by FatherStorm

try adding this to your jQuery(document).ready(function(){

尝试将此添加到您的 jQuery(document).ready(function(){

jQuery('.scrshot').live('click',function(){
   jQuery('.showvid').hide();                 //hide any that might be open
   jQuery(jQuery(this).attr('href')).show(); //show the div we clicked for
});

回答by msmafra

Have you looked at fancybox documentation/blog? http://fancybox.net/blog(4. Show youtube clips.this must help); http://fancybox.net/howto; http://fancybox.net/api;

你看过fancybox文档/博客吗? http://fancybox.net/blog4显示YouTube视频。这必须帮助); http://fancybox.net/howto; http://fancybox.net/api;