簡體   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