- This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
Viewing 3 posts - 1 through 3 (of 3 total)
- The forum ‘JavaScript’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › JavaScript › Ignore function if..?
So I have this top div (#topDiv) that appears when you scroll to almost the bottom of the page, and disappears when you scroll a bit up. There is also a “X” button on it that makes it slide up, but If you scroll it will just slide down again.
This function get’s triggered when you scroll almost at the bottom:
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() > $(document).height() - 500) {
$("#topDiv").slideDown();
$("#pagePush").slideDown(); // Ignore this
}
This function get’s triggered when you scroll a bit up:
if($(window).scrollTop() + $(window).height() < $(document).height() - 800) {
$("#topDiv").slideUp();
$("#pagePush").slideUp();
}
And this function get’s triggered when you click the “X” button:
$("#closeTop").click(function(){
$("#topDiv").slideUp();
$("#pagePush").slideUp();
return false;
});
I want the “closeTop” to ignore the slideDown function, so that it won’t slide down again after you click that button.
Thanks :)
>>DEMO PAGE<<
Is there no kind of “don’t call this function” or “don’t run” in jQuery?
Hi schart!
You could just use a flag to signal that the user had clicked the close button. I modified your code a bit to cache the functions that are called repeatedly (demo):
// cache variables
var win = $(window),
wHeight = win.height(),
dHeight = $(document).height(),
divs = $('#topDiv, #pagePush'),
flag = true; // flag is false when user has manually closed the divs
win
.scroll(function() {
if (flag) {
if ( win.scrollTop() + wHeight > dHeight - 500) {
divs.slideDown();
}
if ( win.scrollTop() + wHeight < dHeight - 800) {
divs.slideUp();
}
}
})
.resize(function(){
// update variables when browser is resized
wHeight = win.height();
dHeight = $(document).height();
});
$("#closeTop").click(function() {
divs.slideUp();
flag = false;
return false;
});