1

我正在使用引导程序设计一个快照应用程序,但它不起作用。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>

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

  <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>

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

我只使用了带有核心依赖项的 Bootstrap 3。

4

0 回答 0