欢迎来到DIVCSS5查找CSS资料与学习DIV CSS布局技术!
  图片 Modal(模态)
  
  本实例演示了如何结合 CSS 和 JavaScript 来一起渲染图片。
  
  首先,我们使用 CSS 来创建 modal 窗口 (对话框), 默认是隐藏的。
  
  然后,我们使用 JavaScript 来显示模态窗口,当我们点击图片时,图片会在弹出的窗口中显示:
  
  实例
  
  // 获取模态窗口
  
  var modal = document.getElementById('myModal');
  
  // 获取图片模态框,alt 属性作为图片弹出中文本描述
  
  var img = document.getElementById('myImg');
  
  var modalImg = document.getElementById("img01");
  
  var captionText = document.getElementById("caption");
  
  img.onclick = function(){
  
  modal.style.display = "block";
  
  modalImg.src = this.src;
  
  modalImg.alt = this.alt;
  
  captionText.innerHTML = this.alt;
  
  }
  
  // Get the <span> element that closes the modal
  
  var span = document.getElementsByClassName("close")[0];
  
  // When the user clicks on <span> (x), close the modal
  
  span.onclick = function() {
  
  modal.style.display = "none";
  
  }

如需转载,请注明文章出处和来源网址:http://www.divcss5.com/css3-style/c64269.shtml