DOM元素全螢幕顯示解決方案,dom全螢幕顯示

來源:互聯網
上載者:User

DOM元素全螢幕顯示解決方案,dom全螢幕顯示

<script type="text/javascript">  function goFullscreen(id) {    // Get the element that we want to take into fullscreen mode    var element = document.getElementById(id);        // These function will not exist in the browsers that don't support fullscreen mode yet,     // so we'll have to check to see if they're available before calling them.        if (element.mozRequestFullScreen) {      // This is how to go into fullscren mode in Firefox      // Note the "moz" prefix, which is short for Mozilla.      element.mozRequestFullScreen();    } else if (element.webkitRequestFullScreen) {      // This is how to go into fullscreen mode in Chrome and Safari      // Both of those browsers are based on the Webkit project, hence the same prefix.      element.webkitRequestFullScreen();   }   // Hooray, now we're in fullscreen mode!  }</script><img class="video_player" src="image.jpg" id="player"></img><button onclick="goFullscreen('player'); return false">Click Me To Go Fullscreen! (For real)</button>


這樣就可以實現全螢幕顯示了,但是DOM元素的尺寸不會改變。別擔心,下面會幫你解決這個問題。


<style type="text/css">  .player:-webkit-full-screen {    width: 100%;    height: 100%;  }  .player:-moz-full-screen {    width: 100%;    height: 100%;  }</style><img class="video_player" src="image.jpg" id="player3"></img><button onclick="goFullscreen('player');">Click Me To Go Fullscreen! (All the way)</button>


這樣對大部分DOM元素都起作用,但是對於iframe元素,還需添加allowFullScreen這個屬性。

<iframe src="iframe_src.html" width="400" height="300" allowFullScreen></iframe>


ok,大功告成!

reference: http://www.jwplayer.com/blog/using-the-browsers-new-html5-fullscreen-capabilities/



在HTML中,開啟的視窗怎訪問與控制父級視窗的Dom的元素?

比如說要找父級視窗中的XX元素

parent.document.getElementById('XX')

就在正常用時前邊加個parent.就代表父級視窗了。
 
DOM子項目問題

<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script>
window.onload=function()
{
var obj=document.getElementsByTagName("div");//取得所有div標籤
alert(obj.length);//這個是顯示所有DIV標籤的個數
}
</script>
</HEAD>

<BODY>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
</BODY>
</HTML>
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.