繁体   English   中英

Javascript函数范围-是否使用console.log?

[英]Javascript function scope - to use console.log or not?

两个功能:

第一:关闭一个固定在页面底部的stickyFooter。

jQuery的:

jQuery(document).ready(function() {
 function closeSticky() {
    jQuery('.stickyFooter').hide();
      jQuery.cookie('stickyNewsClosed', 'yup', {
        path: '/',
        expires: 30
      });
    }
});

第二:此功能淡入/淡出两个格,并在焦点对准输入区域时停止。 现在需要做的是,当stickyfooter关闭时,需要在此单独的函数中调用clearTimeout:

jQuery(document).ready(function () {

    // check if both divs are visible
    if ((jQuery('.footerPromoBannerWrapper').is(':visible')) && (jQuery('.stickyFooter').is(':visible'))) {

        // Local variable for cancel of fades
        var stickyTimeout;

        // Set sticky as display:none
        jQuery('.stickyFooter').hide();

        // Switch in
        window.switchIn = function () {
            jQuery('.footerPromoBannerWrapper').fadeToggle(function () {
                jQuery('.stickyFooter').fadeToggle(function () {
                    stickyTimeout = setTimeout(function () {
                        window.switchOut();
                    }, 3000);
                });
            });
        };

        // Switch out
        window.switchOut = function () {
            jQuery('.stickyFooter').fadeToggle(function () {
                jQuery('.footerPromoBannerWrapper').fadeToggle(function () {
                    stickyTimeout = setTimeout(function () {
                        window.switchIn();
                    }, 3000);
                });
            });
        };

        stickyTimeout = setTimeout(function () {
            window.switchIn();
        }, 5000);

        jQuery('input#emailsignup').focus(function() {
            clearTimeout(stickyTimeout);

        });

    } // End of both divs are visible if statement
});

题:

如何合并两者,以便在粘性页脚关闭时调用timeOut功能? 像这样吗

第一功能修改:

function closeSticky() {
jQuery('.stickyFooter').hide();
jQuery.cookie('stickyNewsClosed', 'yup', {
path: '/',
expires: 30
});
stopAnimation();
}

第二项功能修正:

function stopAnimation() {
jQuery('input#emailsignup').focus(function() {
clearTimeout(stickyTimeout);
});
} // End stopAnimation function
console.log(function stopAnimation());

您在函数内部有jQuery,所以我建议在dom准备就绪范围内移动2个函数。 您的cleartimeout可能正在调用udefined。

暂无
暂无

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

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