Make named anchor bookmarks appear always at top of the screen when clicked

后端 未结 12 574
耶瑟儿~
耶瑟儿~ 2021-01-03 04:21

I have my markup as follows:

  • Sheds & Housing
  • <
    12条回答
    •  野趣味
      野趣味 (楼主)
      2021-01-03 05:20

      A better one (No padding div required!)

      Try with this jsfiddle. Its working perfectly for me.

      Highlights of this fiddle:

      1. No padding div required
      2. Changing height of last wrapper div, only when last link is clicked

      Code below.

      $(document).ready(function(){
        //apply height change while clicking on last link only
        $("ul.sub_navi li a:last").click(function(){
          var $targ= $($(this).attr("href"));
          if($targ.height() < $(window).height()){
            $targ.css('min-height', $(window).height())
          }
        });
      });​
      

    提交回复
    热议问题