简体   繁体   English

Android Native Browser复制HTML5画布(镀铬质量好)

[英]Android Native Browser duplicating HTML5 canvas (fine in chrome)

This is a weird issue that I am only experiencing on a Native browser on Samsung Galaxy Tab 2 and Galaxy S2 in the native browser. 这是一个奇怪的问题,我只在本机浏览器中的Samsung Galaxy Tab 2和Galaxy S2上的Native浏览器上遇到这个问题。

This has also been tested on other android phones and tablets such as the Nexus 7 & Galaxy S4 but their native browser is chrome, so it appears fine. 这也已经在其他Android手机和平板电脑上进行了测试,例如Nexus 7和Galaxy S4,但他们的原生浏览器是镀铬的,所以看起来很好。 This issue is also not present on any IOS browsers, Windows Desktop browsers or Mac Desktop browsers. 任何IOS浏览器,Windows桌面浏览器或Mac桌面浏览器也不存在此问题。

It's almost asif the webpage is loaded twice ontop of itself! 这几乎是因为网页自身加载了两次!

As there is a duplicate canvas element, that updates as the main canvas does. 因为有一个重复的canvas元素,它会像主画布那样更新。

在此输入图像描述在此输入图像描述

Here it appears asthough it only happens when rotated in landscape mode, but I beleive that in portrait mode, the canvas' are perfectly aligned over the top. 在这里它似乎只有在横向模式下旋转才会发生,但我相信在纵向模式下,画布'完全对齐在顶部。

What is even weirder, the menu button that you see is a toggle button, tap to open menu, tap to close menu. 什么是更奇怪的,你看到的菜单按钮是一个切换按钮,点击打开菜单,点击关闭菜单。 On this device when you tap it, it opens and closes instantly. 点击此设备时,它会立即打开和关闭。 the same happens for the mute button toggle. 静音按钮切换也是如此。

I'm completely at a loss. 我完全不知所措。

I have done some javascript debugging throwing in a few alerts here and there, and the initialisation functions that create references to the canvas and so on are only called once. 我已经做了一些javascript调试,在这里和那里抛出一些警报,并且创建对画布的引用的初始化函数等只被调用一次。

I have read and heard about hardware acceleration causing issues, but solutions i've potentially found are only relative to building native apps! 我已经阅读并听说过硬件加速导致问题,但我可能找到的解决方案只与构建本机应用程序有关! not HTML5 Canvas webpages. 不是HTML5 Canvas网页。

Any insight on this could be would be great! 任何有关这方面的见解都可能会很棒! Thanks in advance. 提前致谢。

--EDIT - 编辑

I also put in this test alert(document.getElementsByTagName('canvas').length); 我也把这个测试alert(document.getElementsByTagName('canvas').length);放入alert(document.getElementsByTagName('canvas').length); to see if there was 2 canvas in the DOM but it returns 1! 看看DOM中是否有2个画布,但它返回1!

I ran into this same issue. 我遇到了同样的问题。 I was able to fix this by running the following code after making a change to my canvas: 通过在更改我的画布后运行以下代码,我能够解决这个问题:

// If Samsung android browser is detected
if (window.navigator && window.navigator.userAgent.indexOf('534.30') > 0) {

    // Tweak the canvas opacity, causing it to redraw
    $('canvas').css('opacity', '0.99');

    // Set the canvas opacity back to normal after 5ms
    setTimeout(function() {
        $('canvas').css('opacity', '1');
    }, 5);

}

By tweaking the opacity, this forced the canvas to redraw and removed the duplicate shapes. 通过调整不透明度,这会强制画布重绘并删除重复的形状。 It's a dumb fix but it works. 这是一个愚蠢的修复,但它的工作原理。 Hopefully this helps someone. 希望这有助于某人。

您也可以查看这些技巧的集合: http//slash-system.com/en/how-to-fix-android-html5-canvas-issues/

For double canvas issue there is a bug logged https://code.google.com/p/android/issues/detail?id=35474 you may want to check suggested solutions. 对于双画布问题,有一个错误记录https://code.google.com/p/android/issues/detail?id=35474您可能需要查看建议的解决方案。

In my case this issue appeared only if I had Force GPU rendering enabled. 在我的情况下,只有在启用强制GPU渲染的情况下才会出现此问题。

Issue usually appears if you have some parent element for canvas that has CSS overflow: hidden 如果您有一些具有CSS overflow: hidden canvas的父元素,则通常会出现问题

remove overflow property from all canvas parents,probably we don't need this property on touch devices: 从所有画布父级中删除overflow属性,可能我们在触摸设备上不需要此属性:

$("canvas").parents("*").css("overflow", "visible");

It is well explained at http://slash-system.com/en/how-to-fix-android-html5-canvas-issues/ http://slash-system.com/en/how-to-fix-android-html5-canvas-issues/对此进行了详细解释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM