问题描述
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<link rel="stylesheet" href="">
<script type="text/javascript" src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
</head>
<style type="text/css" media="screen">
html,body,canvas{
padding: 0;
margin: 0;
}
</style>
<body>
<canvas id="heart">
</canvas>
</body>
</html>
<script>
let c = document.getElementById('heart')
let cw = c.width = $(window).width()
let ch = c.height = $(window).height()
</script>
我觉得这样的话应该是canvas
元素和body
元素都应该是屏幕的高度和宽度,但是body
元素比canvas
元素高出4px,导致有滚动条。
解决方法
原因是由于canvas
是行内元素导致的,</canvas>
标签后面跟着的换行导致,这里直接将canvas
变成块级元素即可。
<style type="text/css" media="screen">
html,body,canvas{
padding: 0;
margin: 0;
display: block;
}
</style>