如何自动缩放HTML5 <canvas>
元素以适合页面?
例如,我可以<div>
通过将height
和width
属性设置为100%来进行缩放,但是<canvas>
不会缩放,是吗?
有没有办法使用HTML5 <video>
标签播放全屏视频?
如果这是不可能的,有人知道这个决定是否有理由?
我正在尝试创建一个占用视口宽度和高度100%的画布元素.
你可以在我的例子看到这里正在发生,但它是在Chrome和FireFox中添加滚动条.如何防止额外的滚动条,只提供窗口的宽度和高度作为画布的大小?
我有一个程序,用于在鼠标拖动时在画布上移动对象.但是,我希望画布适合屏幕.我不知道如何实现这一目标.如果我将画布设为"width:100%; height:100%;",则该对象超出范围.
<!doctype html>
<html>
<head>
<link rel="stylesheet" type="text/css" media="all" href="css/reset.css"/> <!-- reset css -->
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js">
</script>
<style>
body{ background-color: ivory; }
canvas{border:1px solid red;}
</style>
<script>
$(function(){
var img = new Image();
img.onload = function(){
ctx.drawImage(img, 0,0);
};
img.src = "http://images.christmastimeclipart.com/images/2/1271716593176_1788/img_1271716593176_17881.jpg";
var canvas=document.getElementById("canvas");
var ctx=canvas.getContext("2d");
var canvasOffset=$("#canvas").offset();
var offsetX=canvasOffset.left;
var offsetY=canvasOffset.top;
var canvasWidth=canvas.width;
var canvasHeight=canvas.height;
var isDragging=false;
// functions to handle mouseup, mousedown, mousemove, mouseout events
$("#canvas").mousedown(function(e){handleMouseDown(e);});
$("#canvas").mousemove(function(e){handleMouseMove(e);});
$("#canvas").mouseup(function(e){handleMouseUp(e);});
$("#canvas").mouseout(function(e){handleMouseOut(e);});
}); // end $(function(){});
</script>
</head>
<body> …
Run Code Online (Sandbox Code Playgroud) html5 ×3
html ×2
javascript ×2
jquery ×2
canvas ×1
css ×1
fullscreen ×1
html5-canvas ×1
video ×1
viewport ×1