jQuery to change content in div based on scroll position

前端 未结 1 1345
自闭症患者
自闭症患者 2020-12-29 01:06

I am building a blog page in Wordpress and adding a sidebar that points to the current post. I\'d like to fill that sidebar with the date of the current post using jQuery. I

相关标签:
1条回答
  • 2020-12-29 01:16

    I do not know where you want to get the date from, so, just an example.. http://jsfiddle.net/Nsubt/

    $(window).on("scroll resize", function(){
        var pos=$('#date').offset();
        $('.post').each(function(){
            if(pos.top >= $(this).offset().top && 
               pos.top < $(this).next().offset().top)
            {
                // any way you want to get the date
                $('#date').html($(this).html()); 
                return; //break the loop
            }
        });
    });
    
    $(document).ready(function(){
      $(window).trigger('scroll'); // init the value
    });
    ​
    

    Div on the right could have a fixed position or you can update its absolute position in the block working with scroll and resize events.

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