本文介绍了如何强制Android的互联网浏览器立即显示风格的变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的三星Galaxy TAB2 7.0平板电脑做了一个简单的HTML抽认卡应用和我体验下Android的互联网浏览器(默认安装)的行为奇怪的问题。当元素的风格发生了变化,如

I made a simple flashcards HTML application and I experience strange problem with behavior under Android internet browser (default installation) on my Samsung Galaxy Tab2 7.0 tablet. When style of element is changed, such as

$(".question").css('color', '#FFFFFF')
$(".answer").css('color', '#FFFFFF')
$(".tag").css('background-color', '#FFFFFF')

浏览器不立即展示任何更改。后来在code我更换容器的文本和计算的大小以适合文本元素。我想这个过程是无形的(这就是为什么我想这样做的白色上白色)。我不能隐藏元素,那么计算是行不通的。

the browser does not make any changes on display immediately. Later in code I am replacing text of containers and calculating sizes to fit text into element. I want this process to be invisible (that's why I want to do this white-on-white). I cannot hide elements, as then calculation would not work.

我的Windows 7与Chrome和IE9下测试这和它的伟大工程在那里。因此,有一些问题,Android浏览器。当我把测试code 警报('调试'); 上面的线条背后,Android浏览器显示了对元素的颜色没有改变的消息,但在Windows下的浏览器7显示消息,如预期的白色上的白色的元素。

I have tested this under Windows 7 with Chrome and IE9 and it works great there. So there is some problem with the Android browser. When I put test code alert('debug'); behind the lines above, the Android browser shows message with no changes on colors on elements, but browsers under Windows 7 show message with white-on-white elements as expected.

我怎么能强迫Android浏览器立即反映这种风格的变化?有一些脚本函数可用于,或某些<&荟萃GT; 标签,将解决这一问题?请指教。

How can I force Android browser to reflect such style changes immediately? Is there some script function available for that, or some <meta> tag that would fix this? Please advise.

推荐答案

当你说你想显示样式的变化立即我猜你的意思是,你的脚本将继续执行,并且希望在屏幕上更新。

When you say you want to "display style changes immediately" I'm guessing you mean that your script is going to continue to execute and you want the screen to update.

您需要使用延续。而不是让你的脚本继续执行,你需要得到继续。您可以通过打破你的code成多种功能做到这一点,每件通过设置超时下一块完成。这里有一个简单的例子。当这是与一个循环完成后,所有的X的出现一次。当使用延续,一个X出现在同一时间。

You need to use continuations. Rather than letting your script keep executing you need to yield and continue. You do this by breaking up your code into multiple functions and each piece finishes by setting a timeout for the next piece. Here's a simple example. When this is done with a loop, all the x's appear at once. When using continuations, one x appears at a time.

<html>
<script>
function using_a_loop() {
   var e = document.getElementById('spot');
   for (var i = 0; i < 1000; ++i) {
      e.innerText += ' x';
   }
}

function using_continuations(i) {
   var e = document.getElementById('spot');
   i = i || 0;  // start at 0 when i not provided
   e.innerText += ' x';
   ++i;
   if (i < 1000) {
       setTimeout(function() { using_continuations(i); }, 0);
   }
}
</script>
<div id="spot">X marks the spot:</div>
<button onclick="using_a_loop()">use a loop</button>
<button onclick="using_continuations()">use continuations</button>
</html>  

这篇关于如何强制Android的互联网浏览器立即显示风格的变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 17:23