M
M
Mikhail Gilmutdinov2016-06-18 12:05:47
css
Mikhail Gilmutdinov, 2016-06-18 12:05:47

How to make elements appear and disappear when scrolling jquery?

jQuery(function(f){
    var element = f('#logocenter');
    f(window).scroll(function(){
        element['fade'+ (f(this).scrollTop() < 100 ? 'In': 'Out')](300);           
    });
});
jQuery(function(d){
    var element = d('#logocenter');
    d(window).scroll(function(){
        element['fade'+ (d(this).scrollTop() > 100 ? 'Out': 'In')](300);           
    });
});

jQuery(function(a){
    var element = a('#nav');
    a(window).scroll(function(){
        element['fade'+ (a(this).scrollTop() > 100 ? 'Out': 'In')](500);           
    });
});


I found these sections of code, but for some reason #nav appears incorrectly, and then disappears.
Yes, and the appearance and disappearance of #logocenter would be desirable in one function.

Has anyone else experienced this, or is there a different way to do it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
Bowen, 2016-06-18
@Mixailhr

Now there is one question left: how can I combine these two functions into one, otherwise it blinks twice)))

Just remove this piece of code:
jQuery(function(d){
    var element = d('#logocenter');
    d(window).scroll(function(){
        element['fade'+ (d(this).scrollTop() > 100 ? 'Out': 'In')](300);           
    });
});

R
Ramazanches, 2021-02-25
@Ramazanches

$(window).scroll( () => {
let windowTop = $(window).scrollTop();
windowTop > 100 ? $('#logocenter').fadeIn(300) : $('#logocenter').fadeOut (300);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question