在 Mobile Safari 上强制全页渲染?

发布于 2024-10-04 04:33:48 字数 1644 浏览 0 评论 0原文

有没有办法强制在 Mobile Safari 上渲染/更新所有页面元素(甚至是屏幕外的元素)?

我正在使用 PhoneGap 构建一个应用程序,并且在尝试通过 JS 更新号码时在 iOS 上遇到问题DOM 元素“存储”在屏幕外。该元素位于 HTML 内,但位于屏幕外,直到按下按钮需要为止。当我按下按钮显示数字时,该元素需要很长时间才能重新出现。

我注意到 Mobile Safari 喜欢渲染页面元素(甚至元素的一部分),因为它们在屏幕上可见。例如,您可以放大图像,它只会渲染可见的部分,如果您滚动到不可见的其他部分,它现在将开始渲染该部分(这需要时间)。

我只是替换 a < 的内容跨度>与一个新的字符串(一个数字),但如果 <跨度>在屏幕外,它似乎不会更新,直到我在屏幕上调用它,然后需要额外的时间来更新。

是否有任何修复/解决方法,或者我应该在将来尝试围绕此进行设计?我觉得很奇怪,我无法在屏幕外动态更改元素并在需要时将它们拉回屏幕上...

HTML:

<div class="menu_container" id="menu_menu">    
<p id="hit_pct"><span class="gold">100</span> Hit %</p>
</div><!-- /#menu_menu -->

menu_menu 通过定位位于屏幕外。然后按下按钮它就会滑入。当 menu_menu 尝试滑入时,它会发出嘎嘎声,因为 span 元素一开始没有出现。然后缓慢渲染并完成幻灯片动画。

我尝试过不使用滑动动画,结果保持不变。该元素的渲染速度不够快,因此整个容器不会在合理的时间内出现。

更新元素的 JavaScript:

if(aTilesHit == 0){
   pct = 100;
}else{
   pct = Math.round((abTilesHit/aTilesHit)*100);
}
x$('#hit_pct').inner('<span class="gold">'+pct+'</span> Hit %');

打开菜单的 JavaScript:

animationsOn = false; //Halts the animations that will be behind the menu
if(x$('.menu_button').hasClass('active')){
   close_menus();
}else{
   x$('#ingameMenus').css({'left':0}); //Positions the menu on screen
   x$('.menu_container').removeClass('hidden'); //.hidden positions the element offscreen. It does NOT add display=hidden
   x$('.menu_button').addClass('active');
}

谢谢, Jordan

注:这种情况不会发生在 Android 浏览器上,因此我觉得这与 Mobile Safari 处理页面渲染的方式直接相关。

Is there a way to force the rendering/updating of all page elements (even those offscreen) on Mobile Safari?

I am building an application using PhoneGap and am experiencing issues on iOS when trying to update a number via JS that is in a DOM element "stored" offscreen. The element is within the HTML but is positioned offscreen until required by pressing a button. When I press the button to show the number, it takes forever for the element to reappear.

I have noticed that Mobile Safari likes to render the page elements (or even sections of elements) as they are visible onscreen. For instance, you can zoom into an image and it will render only the part that is visible and if you scroll over the other section that was not visible it will now begin rendering that (which takes time).

I am just replacing the content of a < span > with a new string (a number) but if the < span > is offscreen it does not seem to get updated until I call it onscreen, which then takes additional time to update.

Is there any fix/workaround to this or should I attempt to design around this in the future? I feel it's rather odd that I can't dynamically change elements offscreen and pull them back onscreen when needed...

HTML:

<div class="menu_container" id="menu_menu">    
<p id="hit_pct"><span class="gold">100</span> Hit %</p>
</div><!-- /#menu_menu -->

menu_menu is located offscreen by positioning. It then slides in on a button press. When menu_menu attempts to slide in, it chugs as the span element does not appear at first. It then renders in slowly and the slide animation completes.

I have tried not using a sliding animation and the result remains the same. The element does not render quickly enough so the whole container does not appear in a reasonable amount of time.

JavaScript that updates the element:

if(aTilesHit == 0){
   pct = 100;
}else{
   pct = Math.round((abTilesHit/aTilesHit)*100);
}
x$('#hit_pct').inner('<span class="gold">'+pct+'</span> Hit %');

JavaScript that opens the menu:

animationsOn = false; //Halts the animations that will be behind the menu
if(x$('.menu_button').hasClass('active')){
   close_menus();
}else{
   x$('#ingameMenus').css({'left':0}); //Positions the menu on screen
   x$('.menu_container').removeClass('hidden'); //.hidden positions the element offscreen. It does NOT add display=hidden
   x$('.menu_button').addClass('active');
}

Thanks,
Jordan

Note: This does not happen on the Android Browser so I feel it is directly related to how Mobile Safari handles page rendering.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

绝對不後悔。 2024-10-11 04:33:48

这可能是移动 Safari 的已知渲染问题。可以通过使用以下CSS规则触发硬件加速来强制渲染:

-webkit-transform: translate3d(0,0,0)

在此问题中讨论:iPad Safari 滚动导致 HTML 元素消失并延迟重新出现

This could be known rendering issue of mobile Safari. Rendering could be forced by triggering hardware acceleration with the following CSS rule:

-webkit-transform: translate3d(0,0,0)

Discussed in this question: iPad Safari scrolling causes HTML elements to disappear and reappear with a delay

2024-10-11 04:33:48

您说它位于屏幕外,您可以隐藏该元素而不是使用 display: none; 吗?

该元素的内容仍然可以通过 JavaScript 访问,但不会显示在屏幕上。

You say it is positioned offscreen, could you just hide the element instead using display: none; ?

The element's content would still be available via JavaScript but would not be on-screen.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文