为什么JQuery不能正确淡化flash对象?

时间:2009-08-04 18:35:40

标签: jquery flash fade

我试图淡出Flash嵌入对象并淡入常规Html。

由于某种原因,fadeout方法的回调在淡出完成之前被多次触发。结果是Html在回调函数中被多次附加,并且它会闪烁一段额外的时间。

当我尝试淡化常规Html时,这不会发生。

fadeout功能不适用于flash吗?

HTML

<a id="HideFlash" href="#">Hide Flash</a>
<div id="FlashContainer" >
    <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0"
        width="100" height="50" id="TEST" align="middle">
        <param name="allowScriptAccess" value="sameDomain" />
        <param name="allowFullScreen" value="false" />
        <param name="movie" value="demo_banner.swf" />
        <param name="quality" value="high" />
        <param name="bgcolor" value="#ffffff" />
        <param name="wmode" value="transparent">
        <embed src="demo_banner.swf" quality="high" wmode="transparent" bgcolor="#ffffff" width="100" height="50" name="TEST"
            align="middle" allowscriptaccess="sameDomain" allowfullscreen="false" type="application/x-shockwave-flash"
            pluginspage="http://www.macromedia.com/go/getflashplayer" />
    </object>
</div>
<div id="RegularContent" >
<h1>Before Fade</h1>
</div>

JQuery的:

 $('#HideFlash').click(function() {
        $('#FlashContainer *').fadeOut('slow', function() {

            $('#FlashContainer').append("<p style='display: none;'>This is in the flash container</p>");
            $('#FlashContainer p').fadeIn('slow');
        });

        $('#RegularContent *').fadeOut('slow', function() {

        $('#RegularContent').append("<p style='display: none;'>This is in the regular content after fade</p>");
        $('#RegularContent p').fadeIn('slow');
        });
    });

5 个答案:

答案 0 :(得分:8)

我认为这是因为jQuery无法操纵第三方多媒体对象的不透明度,即使它嵌入到标准HTML标记中。

你最好的选择可能就是在它上面放置一个尺寸相同的隐形DIV然后只是淡入/淡出(但这只是纯粹的推测)。

答案 1 :(得分:2)

我无法确切地指出问题所在,但我在这里有一个有效的例子: http://jsbin.com/ayoqe

我认为你的jquery选择器中可能是星号*?看起来好像你试图隐藏容器内的所有内容而不是隐藏容器本身。

$(document).ready(function(){ 

  $('#RegularContent').hide(); // hide the regular content on load

  $('#HideFlash').click(function() { 
      $('#FlashContainer').fadeOut('slow'); // fade out the flash container       
      $('#RegularContent').fadeIn('slow'); // fade in the regulare content
      return false; 
  }); 

});


<a id="HideFlash" href="#">Hide Flash</a> 
<div id="FlashContainer" > 
    <object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/AlPqL7IUT6M&hl=en&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/AlPqL7IUT6M&hl=en&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object> 
</div> 
<div id="RegularContent"> 
<h1>Before Fade</h1> 
</div> 

希望有所帮助,我希望我理解正确!

答案 2 :(得分:1)

我的解决方案虽然不能完全相同,但是在fadIn()中使用回调函数将对象标签添加到div。它确实意味着对象本身没有被褪色,但我想假设您可以向div添加图像,然后在fadeIn完成时用目标代码替换图像。

答案 3 :(得分:1)

所以我遇到了同样的问题。将wmode参数更改为“opaque”使其正常工作。

答案 4 :(得分:0)

@dalbaeb答案可能是最好的答案,但奇怪的是它失败了一些丑陋的错误(d在jQuery 1.4中未定义,e在1.5中未定义,看起来代码块与队列处理有关)。

令人惊讶的是,它适用于jQuery 1.3!