Changing div content based on scroll position

前端 未结 1 885
伪装坚强ぢ
伪装坚强ぢ 2020-12-11 19:21

I am hoping for some help using this code from another Stack Exchange post. Below is the javascript:

$(window).on(\"scroll resize\", function(){
    var pos=         


        
相关标签:
1条回答
  • 2020-12-11 20:08

    Add an hidden element inside each section containing the description, for i.e. :

    <div id="content1">
    <p class="description" style="display: none;">content1 description</p>
    ....
    </div>
    

    then in javascript get the description of the relevant section like this:

    if(pos.top >= $(this).offset().top && pos.top <= $(this).next().offset().top)
            {
                $('#date').html($(this).find('.description').text());
                return;
            }
    

    Jsfiddle

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