js 模仿锚点定位的实现方法

下面小编就为大家带来一篇js 模仿锚点定位的实现方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧

如下所示:

<div> <div> <ul> <li><a href="" title="" data-nav="a">A - E</a></li> <li><a href="" title="" data-nav="f">F - L</a></li> <li><a href="" title="" data-nav="m">M - T</a></li> <li><a href="" title="" data-nav="u">U - Z</a></li> </ul> </div> <script type="text/javascript"> $(function(){ var navLinks = $('#scroll_nav').find('a') , target_ul = $('#designer_nav_name') , _top = 0; $.each(navLinks , function( i , elem ){ $(elem).attr('data-to' , i == 0 ? 0 : _top); var id = $(elem).attr('data-nav'); var _h4 = $('#'+id).parent(); _top = parseInt(_h4.next().height()) + _top + parseInt(_h4.height()); $(elem).bind('click', function(){ target_ul[0].scrollTop = $(this).attr('data-to'); return false; }); }); $('#designer_nav_name li').click(function( e ){ var designer_name_href= $(this).find('a').attr("href"); $.getJSON("test.php?action=test&jsoncallback=?&testid="+testidhref,function(data){ $('#Ttai').html(data.catwalk); }); e.preventDefault(); }); }) </script> <div> <h4><a><strong>A</strong></a></h4> <ul> <li></li> </ul> <h4><a><strong>F</strong></a></h4> <ul> <li></li> </ul><h4><a><strong>M</strong></a></h4><ul> <li></li> </ul><h4><a><strong>U</strong></a></h4><ul> <li></li> </ul> </div> </div>

以上这篇js 模仿锚点定位的实现方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wzzjdg.html