Preventing scroll when using URI hash to identify tab

前端 未结 8 1856
陌清茗
陌清茗 2020-12-11 16:05

I\'m using JQuery UI to make tabs in my application. I needed the tabs to be linkable (direct link that opens the page and selects the correct tab). This is done by using a

8条回答
  •  心在旅途
    2020-12-11 16:38

    I tried @mottie solution but is not working now (2 years after).
    It triggers an error: TypeError: tabs is undefined.

    Following is an acceptable solution for me:

    // preventing scroll
    // $("#tabs li a[href^='#tab']").bind('click',function(e){ // less general but better
    $("#tabs li a").bind('click',function(e){
        $("html, body").animate({ scrollTop: 0 });
    });
    

提交回复
热议问题