0
我在畫布內部定位圖像時遇到問題。帆布必須全尺寸。整個事情應該創建一個網頁預加載器。在這種情況下,在css裏面設計圖像不起作用。如何在JavaScript中將畫布中的圖像居中?
<style> canvas{
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #000000;
z-index: 99; }
</style> <body>
<canvas id="c"><img id="logo" width="800" height="150" src="imgsource" alt="logo"></canvas> <div> web content </div>
<script>
jQuery(window).on('load', function() {
jQuery('#c').delay(7000).fadeOut('slow');
jQuery('body').delay(7000).css({'overflow':'visible'});
})
window.onload = function() {
var c = document.getElementById("c");
var ctx = c.getContext("2d");
var img = document.getElementById("logo");
ctx.drawImage(img, 50, 0);
} </script>
設置寬度和畫布 – Isaac
上height屬性當我設置屬性的寬度和高度的圖像消失在畫布上。 – Ols