Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/455.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在javascript中使图像居中于画布内部?_Javascript_Jquery_Html_Css_Canvas - Fatal编程技术网

如何在javascript中使图像居中于画布内部?

如何在javascript中使图像居中于画布内部?,javascript,jquery,html,css,canvas,Javascript,Jquery,Html,Css,Canvas,我在画布内的图像居中时遇到问题。帆布必须是全尺寸的。整个过程应该创建一个web预加载程序。在这种情况下,css内部的图像样式设置不起作用 <style> canvas{ position: fixed; top: 0; left: 0; right: 0; bottom: 0; background-color: #000000; z-index: 99; } </style> <body>

我在画布内的图像居中时遇到问题。帆布必须是全尺寸的。整个过程应该创建一个web预加载程序。在这种情况下,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>

以下仅演示了使用drawImg在画布内对图像进行居中处理。请注意,左边的图像来自html 您的浏览器不支持画布
设置画布上的宽度和高度属性当我在画布上设置属性的宽度和高度时,图像将消失。