【问题标题】:how can I fix the location of html5 canvas element in browser screen?如何修复浏览器屏幕中 html5 canvas 元素的位置?
【发布时间】:2013-08-02 12:07:53
【问题描述】:

如果我调整浏览器的屏幕大小,html5画布创建的动画会移动到浏览器的不同位置,例如,原来的位置在右上角,将浏览器屏幕拖到小尺寸后,该位置在右下角,如何修复浏览器中 html5 画布元素的位置?

【问题讨论】:

  • 请包含产生此问题的代码。

标签: browser html5-canvas


【解决方案1】:

类似:

//Get the canvas &
var c = $('#canv'),    
    container = $(c).parent();

//Run function when browser resizes
$(window).resize( canvasRemake );

function canvasRemake(){ 
    c.attr('width', $(container).width() );
    c.attr('height', $(container).height() );

    //Call a function to redraw other content (texts, images etc)
}

注意:这会杀死你的动画,所以如果浏览器变小,用户将不得不滚动才能看到动画......

只是一点*

【讨论】:

    猜你喜欢
    • 2011-06-22
    • 1970-01-01
    • 1970-01-01
    • 2021-03-19
    • 1970-01-01
    • 2011-02-10
    • 1970-01-01
    相关资源
    最近更新 更多