页面刷新打破Javascript [英] Page refresh breaking Javascript
本文介绍了页面刷新打破Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在运行的脚本出现问题。该脚本添加了基于变量的类,尽管在页面刷新后,它在Chrome上运行(它似乎在firefox上不断运行)。 http://master.blavou.co/test-doc.html
Javascript:
Im currently having a problem with a script I am running. The script adds classes based on a variable although doest work on Chrome after page refresh (it seems to work constantly on firefox). http://master.blavou.co/test-doc.html
Javascript:
$(function() {
var $threes = $('ul img:nth-child(3n+3)');
var $fours = $('ul img:nth-child(3n+4)');
for (var i = 0; i < $fours.length; i++) {
var $three = $threes.eq(i);
var $four = $fours.eq(i);
var result = $three.height() + $four.height();
console.log(result);
if (result == 109) {
$three.addClass('style1a');
$four.addClass('style1b');
} else if (result == 246) {
$three.addClass('style2a');
$four.addClass('style2b');
} else if (result == 177) {
$three.addClass('style3a');
$four.addClass('style3b');
}
}
});
HTML:
HTML:
<ul>
<li>
<img src="http://placehold.it/35x50" />
<img src="http://placehold.it/35x50" />
<img src="http://placehold.it/35x59" />
<img src="http://placehold.it/35x50" />
<img src="http://placehold.it/35x50" />
<img src="http://placehold.it/35x50" />
<img src="http://placehold.it/35x50" />
<img src="http://placehold.it/35x50" />
<img src="http://placehold.it/35x100" />
<img src="http://placehold.it/35x77" />
<img src="http://placehold.it/35x50" />
<img src="http://placehold.it/35x146" />
<img src="http://placehold.it/35x100" />
<img src="http://placehold.it/35x50" />
</li>
</ul>
样式:
Styles:
.style1a, .style1b{
border: 1px solid blue;
}
.style2a, .style2b{
border: 1px solid red;
}
.style3a, .style3b{
border: 1px solid green;
}
推荐答案
(function(){
var
(function() { var
threes =
threes =
(' ul img:nth-child(3n + 3)');
var
('ul img:nth-child(3n+3)'); var
这篇关于页面刷新打破Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文