繁体   English   中英

来自第一个函数的变量的值未反映在第二个函数的值中

[英]The value of the variable from the first function is not reflected in the value of the second

我正在写信给您一个事实,即heigths变量的“ .bottom_down i”函数给出的值不会反映为“ .bottom_up i”。 请帮忙,我是Js的新手

 var heights = 0; $('.bottom_up i').click(function () { heights = heights - window.innerHeight; window.scrollTo(300, heights); alert('Bottom_up ='+ heights); $('.bottom_down').animate({opacity: '1'}, 1200); if (heights = window.innerHeight){ $('.bottom_up').animate({opacity: '0'}, 1200); }else{ $('.bottom_up').animate({opacity: '1'}, 1200); } return false; }); $('.bottom_down i').click(function () { heights = heights + window.innerHeight; window.scrollTo(300, heights); $('.bottom_up').animate({opacity: '1'}, 1200); alert('Bottom_down ='+ heights); }); $(window).scroll(function() { if($(window).scrollTop() + window.innerHeight == $(document).height()) { $('.bottom_down').animate({opacity: '0'}, 1200); } }); 

我认为问题出在这里:

if (heights = window.innerHeight){

无需使用相等运算符检查两个值是否相等,而是为heights分配window.innerHeight的值。

应该是这样的:

if (heights == window.innerHeight){

考虑使用短绒棉纱来避免此类错误,例如ESLint

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM