最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

html2canvas屬性和使用方法以及如何使用html2canvas將HTML內(nèi)容寫(xiě)入Canvas生成圖片

 更新時(shí)間:2020年01月12日 15:47:04   作者:58384View  
為大家介紹一款JS截圖插件html2canvas.js, 它可以通過(guò)純JS對(duì)瀏覽器端經(jīng)行截屏,下面就為大家介紹一下html2canvas.js屬性和具體使用方法,并為大家提供了一個(gè)實(shí)例

如何使用JS截取HTML頁(yè)面為圖片呢,下面為大家介紹一款JS截圖插件html2canvas.js

html2canvas.js 能夠?qū)崿F(xiàn)在用戶瀏覽器端直接對(duì)整個(gè)或部分頁(yè)面進(jìn)行截屏。

html2canvas.js可以將當(dāng)頁(yè)面渲染成一個(gè)Canvas圖片,通過(guò)讀取DOM并將不同的樣式應(yīng)用到這些元素上實(shí)現(xiàn)。

它不需要來(lái)自服務(wù)器任何渲染,整張圖片都是在客戶端瀏覽器創(chuàng)建。當(dāng)

瀏覽器不支持Canvas時(shí),將采用Flashcanvas或ExplorerCanvas技術(shù)代替實(shí)現(xiàn)。

以下瀏覽器能夠很好的支持該腳本:Firefox 3.5+, Google Chrome, Opera新的版本, IE9以上的瀏覽器。

基本語(yǔ)法

html2canvas(element, options);
html2canvas(document.body, {
 onrendered: function(canvas) {
  var url = canvas.toDataURL();//圖片地址
  document.body.appendChild(canvas);
 },
 width: 300,
 height: 300

或者使用ES6的promise

//兩個(gè)參數(shù):所需要截圖的元素id,截圖后要執(zhí)行的函數(shù), canvas為截圖后返回的最后一個(gè)canvas html2canvas(document.getElementById('id')).then(function(canvas) {document.body.appendChild(canvas);});

html2canvas基本參數(shù)說(shuō)明

參數(shù)名稱(chēng) 類(lèi)型 默認(rèn)值 描述
allowTaint boolean false Whether to allow cross-origin images to taint the canvas---允許跨域
background string #fff Canvas background color, if none is specified in DOM. Set undefined for transparent---canvas的背景顏色,如果沒(méi)有設(shè)定默認(rèn)透明
height number null Define the heigt of the canvas in pixels. If null, renders with full height of the window.---canvas高度設(shè)定
letterRendering boolean false Whether to render each letter seperately. Necessary if letter-spacing is used.---在設(shè)置了字間距的時(shí)候有用
logging boolean false Whether to log events in the console.---在console.log()中輸出信息
proxy string undefined Url to the proxy which is to be used for loading cross-origin images. If left empty, cross-origin images won't be loaded.---代理地址
taintTest boolean true Whether to test each image if it taints the canvas before drawing them---是否在渲染前測(cè)試圖片
timeout number 0 Timeout for loading images, in milliseconds. Setting it to 0 will result in no timeout.---圖片加載延遲,默認(rèn)延遲為0,單位毫秒
width number null Define the width of the canvas in pixels. If null, renders with full width of the window.---canvas寬度
useCORS boolean false Whether to attempt to load cross-origin images as CORS served, before reverting back to proxy--這個(gè)我也不知道是干嘛的

例子

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>html2canvas example</title>
  <script type="text/javascript" src="html2canvas.js"></script>
</head>
<script type="text/javascript">
function takeScreenshot() {
 console.log('test');
  html2canvas(document.getElementById('view'), {
    onrendered: function(canvas) {
      document.body.appendChild(canvas);
    },
   // width: 300,
   // height: 300
  });
}
</script>
<body>
  <div id="view" style="background:url(test.jpg) 50%; width: 700px; height: 500px;">
    <input type="button" value="截圖" onclick="takeScreenshot()">
  </div>
</body>

</html>

效果圖如下:

截圖效果如下:

最后附上html2canvas官網(wǎng)鏈接

官網(wǎng)

Github

相關(guān)文章

最新評(píng)論

三河市| 汝州市| 旬邑县| 池州市| 贵定县| 衡阳市| 淮北市| 云梦县| 邮箱| 铜陵市| 黑河市| 阜宁县| 绥滨县| 会同县| 临夏市| 武定县| 清水河县| 车致| 石台县| 菏泽市| 夏津县| 久治县| 犍为县| 金溪县| 泸水县| 通河县| 金沙县| 开江县| 镇康县| 台北县| 介休市| 海伦市| 镇雄县| 丰县| 宕昌县| 泌阳县| 沙洋县| 郧西县| 福建省| 江津市| 嘉定区|