0

我有一个博客,我希望在页面加载后加载 youtube 和 vimeo 视频,因为到目前为止,这些视频阻止了其余内容的加载。

这是我为每个帖子生成的代码:

public function generateVimeoVideo($class){

    return "<iframe class='".$class."' src='//player.vimeo.com/video/".$this->vimeo_video_id."' frameborder='0' webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>";


}

onload 后如何加载?

4

5 回答 5

0

试试这个jquerybind

    <!DOCTYPE html>
    <html>
    <head>
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">

      <script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>


      <style type='text/css'>
        body {background-color:#222;}

    #frameContainer {
      background:white url('http://hompimpa.googlecode.com/svn/trunk/images/loading.gif') no-repeat 50% 50%;
      margin:30px;
    }

    #frameContainer iframe {
      display:block;
      padding:5%;
      border:none !important;
    }

      </style>



    <script type='text/javascript'>//<![CDATA[ 

    $(window).bind("load", function() {
       $('#frameContainer').html('<iframe src="//player.vimeo.com/video/" + $vid + " frameborder="0" width="90%" height="220px" scrolling="auto"></iframe>'); 
    });

    //]]>  

    </script>

</head>
<body>
  <div id="frameContainer"></div>


</body>


</html>
于 2013-08-30T11:04:42.377 回答
0

基本上捕获由generateVimeoVideo($class)()javascript 变量返回的值,并在您的 dom 加载后才在您显示的页面上创建 iframe 元素。

于 2013-08-30T10:47:16.757 回答
0

这很简单。

请在点击事件上执行该功能。

function change_frame(){
document.getElementById("captchaDiv").src='http://www.domain.com/captcha.php?'+(new Date()).getMilliseconds();
return true;
}


<a href='#' onClick="change_frame();return false" />

希望它工作!

于 2013-08-30T10:47:44.703 回答
0

它应该像这个 HTML 一样工作,请检查它并给我回复。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script type="text/javascript">
<!--
function loadFrame(){
document.getElementById('theframe').innerHTML='<iframe src="http://www.w3schools.com/" width="500" height="300" frameborder="0" scrolling="auto"></iframe>';
}
//-->
</script>
</head>

<body>
<span id="theframe"><noscript><iframe src="http://www.w3schools.com/" width="500" height="300" frameborder="0" scrolling="auto"></iframe></noscript></span><br>
The rest of your page here.
<script type="text/javascript">
<!--
onload=loadFrame;
//-->
</script>
</body>
</html>

谢谢,

于 2013-08-30T10:54:50.757 回答
0
<?php 


?>
<html>
<body>
<script>
  function generateVimeoVideo($class,$vid){
    var putYouTubeHere= document.getElementById('putYouTubeHere');
    putYouTubeHere.innerHTML=  "<iframe class='" + $class + "' src='//player.vimeo.com/video/" + $vid + "' frameborder='0' webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>";


}
document.addEventListener( "DOMContentLoaded", function(){ generateVimeoVideo('classname','<?php  echo $this->vimeo_video_id;?>');}, false );
</script>
<div  id="putYouTubeHere"></div>
</body></html>
于 2013-08-30T10:55:46.530 回答