所以我决定使用一个简单的1行jQuery内容滑块,而不是选择臃肿的插件。我使用animated.css作为淡入/淡出幻灯片的jQuery文本淡入淡出。简单的jquery幻灯片导致高CPU使用
HTML:
<section id="student-blocks">
<div>
<h2 class="animated fadeUp">News Item #1</h2>
<p "animated fadeIn">lorem</p>
</div>
<div>
<h2 class="animated fadeUp">News Item #2</h2>
<p "animated fadeIn">lorem</p>
</div>
<div>
<h2 class="animated fadeUp">News Item #3</h2>
<p "animated fadeIn">lorem</p>
</div>
</section>
JQuery的:
$(function()
{
$("#student-blocks > div:gt(0)").hide();
setInterval(function()
{
$('#student-blocks > div:first')
.hide()
.next()
.fadeIn()
.end()
.appendTo('#student-blocks');
}, 4000);
});
PAGE托管的位置:http://cloud69.comoj.com/pages/
的问题
此幻灯片会导致我的CPU使用率高达15%到20%。我尝试收集一个CPU配置文件,并定期看到尖峰(可能在幻灯片发生变化时)。
为什么CPU使用率如此之高?我如何让它变得更好?
我会在这里选择'.appendTo()'作为罪魁祸首。 – melancia 2014-09-28 07:48:03
尝试使用'.html()'来代替它,看看它是否有帮助。 – melancia 2014-09-28 07:51:04
另一个变化是将选择器缓存到一个变量中,所以你不需要每次都选择它:var myItem = $('#student-blocks')'var'myFirstItem = $('#student-blocks > div:第一个')'。围绕这些线路的东西。 – melancia 2014-09-28 07:51:54