使Bootstrap 3与getUserMedia()兼容

时间:2013-09-10 17:49:39

标签: javascript html5 css3 twitter-bootstrap-3 getusermedia

我正在使用引导程序设置快照应用程序,但它无法正常工作。 snapshop应用程序独立运行作为原始代码。就是这样:

<button>Take snapshot</button>   
<br />
<video autoplay  ></video>
<canvas ></canvas>
<script>
  var idx = 0;
  var filters = ['','grayscale', 'sepia', 'blur', 'brightness', 'contrast', 'hue-rotate',
                 'opacity', 'drop-shadow', 'saturate', 'invert'];

  function changeFilter(e) {
    var el = e.target;
    el.className = '';
    var effect = filters[idx++ % filters.length]; // loop through filters.
    if (effect) {
      el.classList.add(effect);
    }
  }

  document.querySelector('video').addEventListener('click', changeFilter, false);
  document.querySelector('canvas').addEventListener('click', changeFilter, false);
</script>
<!-- img  id="hu" src="" -->

<script>
  // Put event listeners into place
  window.addEventListener("DOMContentLoaded", function() {

    var video = document.querySelector('video');
    var button = document.querySelector('button');
    var canvas = document.querySelector('canvas');
    var ctx = canvas.getContext('2d');
    var onFail = function(error) {
      alert('\t\t\t\t\tSorry. \nIt seems you (or your browser) rejected access. \n\t\tCheck the FAQ for solutions. \nThe error is: ' + error);
      console.log('Video Capture Error: ', error.code);
    };
    // create snapshot function        
    function snapshot() {
           // set the canvas to the dimensions of the video
           canvas.width = video.clientWidth;
           canvas.height = video.clientHeight;    
           ctx.drawImage(video, 0, 0);
        }
    // navigator.getUserMedia  = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
    if (navigator.getUserMedia) {
      navigator.getUserMedia({video: true}, function(stream) {
      video.src = window.URL.createObjectURL(stream);
      button.addEventListener('click', snapshot, false);
      },onFail);
    } else if (navigator.webkitGetUserMedia) {
      navigator.webkitGetUserMedia({video: true}, function(stream) {
      video.src = window.webkitURL.createObjectURL(stream);
      button.addEventListener('click', snapshot, false);
      },onFail);
    } else if (navigator.mozGetUserMedia) {
      navigator.mozGetUserMedia({video: true}, function(stream) {
      video.src = window.mozURL.createObjectURL(stream);
      button.addEventListener('click', snapshot, false);
      },onFail);
    } else if (navigator.msGetUserMedia) {
      navigator.msGetUserMedia({video: true}, function(stream) {
      video.src = window.msURL.createObjectURL(stream);
      button.addEventListener('click', snapshot, false);
      },onFail);
    } else {
      // getUserMedia not supported, fallback video information plus alert...
      video.src = 'assets/vid/fallback.webm';
      video.src = 'assets/vid/fallback.';
      video.src = 'assets/vid/fallback.';
    }

  }, false);
</script>

当我将此默认导航栏添加到“body”正下方的页面顶部时,快照将停止工作:

  <div class="row">
    <nav class="navbar navbar-default" role="navigation">
      <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-target=".navbar-ex1-collapse" data-toggle="collapse">
          <span class="sr-only">Toggle navigation</span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </button>
        <a class="navbar-brand" href="#">Brand</a>
      </div>
      <div class="collapse navbar-collapse navbar-ex1-collapse">
        <ul class="nav navbar-nav">
          <li class="active"><a href="#">Link</a></li>
          <li><a href="#">Link</a></li>
          <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret"></b></a>
            <ul class="dropdown-menu">
              <li><a href="#">Action</a></li>
              <li><a href="#">Another action</a></li>
              <li><a href="#">Something else here</a></li>
              <li><a href="#">Separated link</a></li>
              <li><a href="#">One more separated link</a></li>
            </ul>
          </li>
        </ul>
        <form class="navbar-form navbar-left" role="search">
          <div class="form-group">
            <input type="text" class="form-control" placeholder="Search">
          </div>
          <button type="submit" class="btn btn-default">Submit</button>
        </form>
        <ul class="nav navbar-nav navbar-right">
          <li><a href="#">Link</a></li>
          <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret"></b></a>
            <ul class="dropdown-menu">
              <li><a href="#">Action</a></li>
              <li><a href="#">Another action</a></li>
              <li><a href="#">Something else here</a></li>
              <li><a href="#">Separated link</a></li>
            </ul>
          </li>
        </ul>
      </div>
    </nav>
  </div>

我发现“canvas”元素丢失或丢失,我的浏览器很难。 我在Debian Linux上使用Chromium(Ubuntu 12.04)。

我只使用了Bootstrap 3和核心依赖项。

0 个答案:

没有答案