CSS CSS Media Targeted JavaScript

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CSS CSS Media Targeted JavaScript相关的知识,希望对你有一定的参考价值。

<div id="mediaInspector"></div>

<style type="text/css">
  #mediaInspector {
    display:none
  }
  @media aural {
    #mediaInspector { z-index: 1 }
  }
  @media braille {
    #mediaInspector { z-index: 2 }
  }
  @media embossed {
    #mediaInspector { z-index: 3 }
  }
  @media handheld {
    #mediaInspector { z-index: 4 }
  }
  @media print {
    #mediaInspector { z-index: 5 }
  }
  @media projection {
    #mediaInspector { z-index: 6 }
  }
  @media screen {
    #mediaInspector { z-index: 7 }
  }
  @media tty {
    #mediaInspector { z-index: 8 }
  }
  @media tv {
    #mediaInspector { z-index: 9 }
  }
</style>

<script type="text/javascript">
  var mediaInspector = document.getElementById('mediaInspector');
  if (mediaInspector.currentStyle) {
    zIndex = mediaInspector.currentStyle['zIndex'];
  } else if (window.getComputedStyle) {
    zIndex = window.getComputedStyle(mediaInspector, '').getPropertyValue("z-index");
  }
  switch (parseInt(zIndex)) {
    case 1:
      // @media aural code
	  alert('@media aural code');
      break;
    case 2:
      // @media braille code
	  alert('@media braille code');
      break; 
    case 3:
      // @media embossed code
	  alert('@media embossed code');
      break;
    case 4:
      // @media handheld code
	  alert('@media handheld code');
      break;
    case 5:
      // @media print code
	  alert('@media print code');
      break;
    case 6:
      // @media projection code
	  alert('@media projection code');
      break;
    case 7:
      // @media screen code
	  alert('@media screen code');
      break;
    case 8:
      // @media tty code
	  alert('@media tty code');
      break;
    case 9:
      // @media tv code
	  alert('@media tv code');
      break;
  }
</script>

以上是关于CSS CSS Media Targeted JavaScript的主要内容,如果未能解决你的问题,请参考以下文章

css EP3-SAMPLE2-ja.css

CSS-@media和rem

css Bootstrap Media CSS |萨斯

css Unyson media queries.css

css @ media.css

css @ media.css