Fade text when page scrolls

后端 未结 4 1270
Happy的楠姐
Happy的楠姐 2021-02-06 18:33

I have this basic example working:

http://www.mharrisweb.co.uk/tester.htm

Is there anyway I can get the fading text to scroll slightly, to create a more fluid tr

相关标签:
4条回答
  • 2021-02-06 18:54

    Just manipulate the margins of the text like you did the opacity.

    Example:

    jQuery(function($) {
        var divs = $('.fade');
        $(window).on('scroll', function() {
            var st = $(this).scrollTop();
            divs.css({ 
                'margin-top' : -(st/3)+"px", 
                'opacity' : 1 - st/35
            }); 
        });
    });
    
    0 讨论(0)
  • 2021-02-06 18:55

    use this

    var divs = $('.social, .title');
    $(window).scroll(function(){
       if($(window).scrollTop()<10){
             divs.stop(true,true).fadeIn("fast");
       } else {
             divs.stop(true,true).fadeOut("fast");
       }
    });
    
    0 讨论(0)
  • 2021-02-06 18:56

    Here is something that combines a few of the ideas already discussed.

    $(window).scroll(function(){
        var top = ($(window).scrollTop() > 0) ? $(window).scrollTop() : 1;
        $('.fade').stop(true, true).fadeTo(0, 1 / top);
        $('.fade').css('top', top * 1.3);             
    });
    

    jsfiddle

    0 讨论(0)
  • 2021-02-06 19:02

    Use this:

    http://api.jquery.com/animate/

    It allows you to smoothly move the element to a given coordinates, which you can determine using:

    http://api.jquery.com/scrollTop/

    Also you will need this:

    http://api.jquery.com/fadeTo/

    It allows you to fade to a particular transparency, instead of all the way to fully transparent. You will need this if you want it to look like the "themetrust.com" example you gave, if you notice if you only scroll a little, it only fades a little

    0 讨论(0)
提交回复
热议问题