简体   繁体   English

naturalHeight与naturalWidth的比较

[英]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.

相关问题 naturalHeight 和 naturalWidth Javascript 的问题 - problem with naturalHeight and naturalWidth Javascript naturalHeight 和 naturalWidth 属性是新增的还是已弃用? - naturalHeight and naturalWidth property new or deprecated? naturalWidth 和 naturalHeight 使用 onload 事件返回 0 - naturalWidth and naturalHeight returns 0 using onload event Random 尝试获取图像的 naturalHeight 和 naturalWidth 失败 - Random fails trying to get the naturalHeight and naturalWidth of an image 为什么无法在javascript / JQuery中获取图像的naturalHeight / naturalWidth? - Why can't I get the naturalHeight/naturalWidth of an image in javascript/JQuery? 从 onLoad() 返回的 React 合成事件<image>里面的元素<svg>没有 naturalWidth 或 naturalHeight 属性 - React synthetic event returned from onLoad() of <image> element inside <svg> does not have naturalWidth or naturalHeight properties javascript事件:当图像开始加载时挂钩(已经有自然宽度和自然高度道具但尚未加载自身) - javascript event: hook when image starts loading ( already has naturalWidth & naturalHeight props but haven't loaded itself yet) Firefox .naturalHeight属性 - Firefox .naturalHeight property 与 .naturalWidth 相关的 Chrome 错误? - Chrome bug related to .naturalWidth? image naturalWidth返回零 - image naturalWidth return zero
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM