[英]Javascript function scope - to use console.log or not?
Two functions: 两个功能:
First: Closes a stickyFooter that is fixed to the bottom of the page onclick of the cross. 第一:关闭一个固定在页面底部的stickyFooter。
jQuery: jQuery的:
jQuery(document).ready(function() {
function closeSticky() {
jQuery('.stickyFooter').hide();
jQuery.cookie('stickyNewsClosed', 'yup', {
path: '/',
expires: 30
});
}
});
Second: This function fades in/fades out two divs, and stops when there's focus to an input area. 第二:此功能淡入/淡出两个格,并在焦点对准输入区域时停止。 What needs to happen now is when the stickyfooter is closed it needs to call the clearTimeout in this separate function: 现在需要做的是,当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
});
Question: 题:
How do I combine both in order to call the timeOut feature as part of the close of the sticky footer? 如何合并两者,以便在粘性页脚关闭时调用timeOut功能? Something like this? 像这样吗
First function amendment: 第一功能修改:
function closeSticky() {
jQuery('.stickyFooter').hide();
jQuery.cookie('stickyNewsClosed', 'yup', {
path: '/',
expires: 30
});
stopAnimation();
}
Second function amendment: 第二项功能修正:
function stopAnimation() {
jQuery('input#emailsignup').focus(function() {
clearTimeout(stickyTimeout);
});
} // End stopAnimation function
console.log(function stopAnimation());
You have jQuery inside the functions, so i would suggest moving the 2 functions inside the dom ready scope. 您在函数内部有jQuery,所以我建议在dom准备就绪范围内移动2个函数。 Your cleartimeout is probably calling in udefined. 您的cleartimeout可能正在调用udefined。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.