js 模仿锚点定位的实现方法
如下所示:
<divclass="designer-bgov"> <divclass="w-77f-ldesigner-nav"> <ulid="scroll_nav"> <liclass="designer-nav-li"><ahref=""title=""data-nav="a">A-E</a></li> <liclass="designer-nav-li"><ahref=""title=""data-nav="f">F-L</a></li> <liclass="designer-nav-li"><ahref=""title=""data-nav="m">M-T</a></li> <liclass="designer-nav-li"><ahref=""title=""data-nav="u">U-Z</a></li> </ul> </div> <scripttype="text/javascript"> $(function(){ varnavLinks=$('#scroll_nav').find('a'),target_ul=$('#designer_nav_name'),_top=0; $.each(navLinks,function(i,elem){ $(elem).attr('data-to',i==0?0:_top); varid=$(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'); returnfalse; }); }); $('#designer_nav_nameli').click(function(e){ vardesigner_name_href=$(this).find('a').attr("href"); $.getJSON("test.php?action=test&jsoncallback=?&testid="+testidhref,function(data){ $('#Ttai').html(data.catwalk); }); e.preventDefault(); }); }) </script> <divclass="f-rdesigner-index"id="designer_nav_name"> <h4><aname="a"id="a"><strong>A</strong></a></h4> <ul> <li></li> </ul> <h4><aname="f"id="f"><strong>F</strong></a></h4> <ul> <li></li> </ul><h4><aname="m"id="m"><strong>M</strong></a></h4><ul> <li></li> </ul><h4><aname="u"id="u"><strong>U</strong></a></h4><ul> <li></li> </ul> </div></div>
以上这篇js模仿锚点定位的实现方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。