加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
本帖最后由 play337 于 2021-10-20 17:18 编辑
我如何讓10秒後自動更改遊戲視窗大小呢?
<canvas width="800" height="600" id="canvas" oncontextmenu="event.preventDefault()" style="width: 800px; height: 600px;"></canvas>
經過十秒
<canvas width="600" height="400" id="canvas" oncontextmenu="event.preventDefault()" style="width: 600px; height: 400px;"></canvas>
-----------------------------------------------------
<script> setTimeout("alert('對不起, 要你久候')", 30000 ) document.getElementById('canvas').width = '600px'; document.getElementById('canvas').height = '400px'; document.getElementById('canvas').style.width = '600px'; document.getElementById('canvas').style.height = '400px'; </script>
<script>
setTimeout("alert('對不起, 要你久候')", 30000 )
document.getElementById('canvas').width = '600px';
document.getElementById('canvas').height = '400px';
document.getElementById('canvas').style.width = '600px';
document.getElementById('canvas').style.height = '400px';
</script>
結果甚麼事情也沒有發生....
<script> setTimeout("alert('對不起, 要你久候')", 15000 ) document.getElementById('canvas').width = 600; document.getElementById('canvas').height = 400; </script>
<script>
setTimeout("alert('對不起, 要你久候')", 15000 )
document.getElementById('canvas').width = 600;
document.getElementById('canvas').height = 400;
</script>
還是甚麼事情都沒發生.....
window.onload = function() { function resize() { let canvas = document.querySelector('canvas') let ww = window.innerWidth let wh = window.innerHeight let wRatio = ww / wh let gameRatio = config.width / config.height if (wRatio < gameRatio) { canvas.style.width = ww + 'px' canvas.style.height = ( ww / gameRatio ) + 'px' } else { canvas.style.width = ( wh * gameRatio ) + 'px' canvas.style.height = wh + 'px' } } resize() window.addEventListener('resize', resize, false) // 偵聽事件 resize }
window.onload = function() {
function resize() {
let canvas = document.querySelector('canvas')
let ww = window.innerWidth
let wh = window.innerHeight
let wRatio = ww / wh
let gameRatio = config.width / config.height
if (wRatio < gameRatio) {
canvas.style.width = ww + 'px'
canvas.style.height = ( ww / gameRatio ) + 'px'
} else {
canvas.style.width = ( wh * gameRatio ) + 'px'
canvas.style.height = wh + 'px'
}
}
resize()
window.addEventListener('resize', resize, false) // 偵聽事件 resize
}
後來找到這個好像很棒的東西...他說可以自己更改遊戲大小... 但是 還是甚麼事情都沒有發生... >_<
------------------------------------------------------
有沒有辦法弄個可以拉動的條....很簡單的改變遊戲視窗大小呢?
如果不能有可以拉動的條...不然就幾個我給定固定大小的按鈕好了.... |