[英]naturalHeight comparison with naturalWidth
I'm trying to compare the height and width of a series of images kept in a list. 我正在尝试比较列表中保存的一系列图像的高度和宽度。 However upon running this, the 'if' statement runs the "else" console.log in every instance.
但是,运行此命令后,“ if”语句将在每个实例中运行“ else” console.log。
no other errors are shown. 没有显示其他错误。 According to chrome debugger, all the images have a 'naturalHeight' and 'naturalWidth' numerical value set.
根据chrome调试器,所有图像均设置了“ naturalHeight”和“ naturalWidth”数值。
Can anyone help me out? 谁能帮我吗?
setImgSize(myList); function setImgSize(list){ var elementChildren = list.children; for (var i = 0; i < elementChildren.length; i++) { if (list.children[i].children[0].natualHeight > list.children[i].children[0].natualWidth){ console.log("is Heigher"); } else if (list.children[i].children[0].natualHeight <= list.children[i].children[0].natualWidth){ console.log("is Longer"); } else { console.log("bypassed"); }; }; }
<ul id="myList"> <li class="lfwImg"><img src="images/LFW/_MG_5664ed.jpg"></img></li> <li class="lfwImg"><img src="images/LFW/_MG_5945ed.jpg"></img></li> <li class="lfwImg"><img src="images/LFW/_MG_5334ed.jpg"></img></li> <li class="lfwImg"><img src="images/LFW/_MG_6067ed.jpg"></img></li> <li class="lfwImg"><img src="images/LFW/_MG_4280ed.jpg"></img></li> <li class="lfwImg"><img src="images/LFW/_MG_6367ed.jpg"></img></li> <li class="lfwImg"><img src="images/LFW/_MG_5141ed.jpg"></img></li> <li class="lfwImg"><img src="images/LFW/_MG_2823ed.jpg"></img></li> <li class="lfwImg"><img src="images/LFW/_MG_4501ed.jpg"></img></li> </ul>
natualHeight
Look veeeeeeery closely at that word... =) 仔细看看veeeeeeery这个词... =)
It's probably just finding that NaN
is neither less than nor greater than nor equal to NaN
. 可能只是发现
NaN
既不小于也不大于也不等于NaN
。 (You have the same typo on naturalWidth too) (您在naturalWidth上也有相同的错字)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.