js实现延时加载Flash的方法

当页面中包含自动播放视频的flash播放器时,flash的流媒体播放会一直不停的下载视频(哪怕你点击了播放暂停/停止也一样在不停下载),这样会影响到页面其它元素的加载。

最简单的优化办法就是让Flash一开始不要播放:当然,你可以修改fla源文件,让视频播放一开始就处于暂停,直到用户点击了播放按钮。但问题是,如果您嵌入的是没有源文件的flash动画,这种路子就走不通了。

思路

可以先在放置flash的地方,放一张小图片,点击图片后再把图片元素换成对应的object标签。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>swf占位符</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type="text/javascript" src="https://ajax.microsoft.com/ajax/jQuery/jquery-1.4.2.min.js"></script> <script type="text/javascript"> $().ready(function () { $("#rbtvs_play_pos").click(function () { $("#swfPos").html("<object classid=https://www.jb51.net/article/\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=https://www.jb51.net/article/\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0\" width=https://www.jb51.net/article/\"226\" height=https://www.jb51.net/article/\"338\" id=https://www.jb51.net/article/\"rbtvs_player\" align=https://www.jb51.net/article/\"middle\" style=https://www.jb51.net/article/\"z-index: -999\"><param name=https://www.jb51.net/article/\"allowScriptAccess\" value=https://www.jb51.net/article/\"Always\" /><param name=https://www.jb51.net/article/\"allowFullScreen\" value=https://www.jb51.net/article/\"false\" /><param name=https://www.jb51.net/article/\"movie\" value=https://www.jb51.net/article/\"http://img.rbtvs.com/swf/rbtvs_player.swf\" /><param name=https://www.jb51.net/article/\"quality\" value=https://www.jb51.net/article/\"high\" /><param name=https://www.jb51.net/article/\"bgcolor\" value=https://www.jb51.net/article/\"#efefef\" /><param name=https://www.jb51.net/article/\"wmode\" value=https://www.jb51.net/article/\"opaque\" /><embed src=https://www.jb51.net/article/\"http://img.rbtvs.com/swf/rbtvs_player.swf\" quality=https://www.jb51.net/article/\"high\" bgcolor=https://www.jb51.net/article/\"#efefef\" width=https://www.jb51.net/article/\"226\" height=https://www.jb51.net/article/\"338\" name=https://www.jb51.net/article/\"rbtvs_player\" align=https://www.jb51.net/article/\"middle\" allowscriptaccess=https://www.jb51.net/article/\"Always\" allowfullscreen=https://www.jb51.net/article/\"false\" type=https://www.jb51.net/article/\"application/x-shockwave-flash\" pluginspage=https://www.jb51.net/article/\"http://www.adobe.com/go/getflashplayer\" /></object>"); }) }) </script> </head> <body> <div> <img src="https://img.rbtvs.com/bihu001/images/rbtvs_play.gif" alt="点击播放视频" /> </div> </body> </html>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wgzddz.html