【发布时间】:2017-07-16 21:59:30
【问题描述】:
在画布内居中图像时遇到问题。画布必须是全尺寸的。整个事情应该创建一个网络预加载器。在这种情况下,css 内的样式图像不起作用。
<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>
【问题讨论】:
-
设置画布的宽高属性
-
当我在画布上设置属性的宽度和高度时,图像消失了。
标签: javascript jquery html css canvas