簡體   English   中英

如何使用Javascript檢測SVG動畫和顯示/隱藏Flash / SVG對象?

[英]How do I use Javascript to detect SVG Animation and Show/Hide Flash/SVG objects?

我一直在嘗試使用SMIL創建SVG動畫。 它在最新的Firefox中運行良好,但當然它在IE中不起作用。 我已經有了類似的Flash動畫。 我的計划是在頁面上包含Flash和SVG動畫,並根據javascript檢測顯示/隱藏它們。 但我對javascript很恐怖,並且不知道該怎么做。 我將使用鏈接的.js文件。 我的計划是在頁面加載時檢測瀏覽器是否支持“http://www.w3.org/TR/SVG11/feature#AnimationEventsAttribute”功能,如果支持,則隱藏Flash對象(id =“rotateFlash “)並顯示SVG對象(id =”rotateSVG“)。

我不知道是否有更好的方法來實現我想要的東西,而且我還沒有找到任何類似於我想要實現的代碼。 我發現了顯示/隱藏javascripts,但不知道如何用它們來實現檢測該功能。

這段代碼似乎至少做了一些事情,但它似乎遵循“else”命令,我猜這意味着Firefox沒有將該功能檢測為“True”(IE9也不是,但這是預期的)。

function supportsSvg() {
  if(document.implementation.hasFeature ("http://www.w3.org/TR/SVG11/feature#AnimationEventsAttribute", "1.0") == "true" ) {
    document.getElementById("rotateSVG").style.display = "";
    document.getElementById("rotateFlash").style.display = "none";
  }
  else {
    document.getElementById("rotateSVG").style.display = "none";
    document.getElementById("rotateFlash").style.display = "";
  }
}

我不知道還能做什么。 我嘗試過其他更簡單的SVG功能,但我得到了相同的結果。 我一直在閱讀有關Modernizr的內容,但對我來說這似乎太復雜了。 我不明白為什么,如果它會起作用。

我想我終於開始工作了。 查看代碼后,我有一種感覺== "true"是不必要的,所以我刪除了它。 現在它似乎在Firefox 13和IE9中運行。

function supportsSvg() {
  if(document.implementation.hasFeature ("http://www.w3.org/TR/SVG11/feature#AnimationEventsAttribute", "1.0")) {
    document.getElementById("rotateSVG").style.display = "";
    document.getElementById("rotateFlash").style.display = "none";
  }
  else {
    document.getElementById("rotateSVG").style.display = "none";
    document.getElementById("rotateFlash").style.display = "";
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM