JQuery UI Tabs Causing Screen to “Jump”

后端 未结 17 1769
生来不讨喜
生来不讨喜 2020-11-30 22:22

I\'m using the latest version of the jQuery UI tabs. I have tabs positioned toward the bottom of the page.

Every time I click a tab, the screen jumps toward the top

相关标签:
17条回答
  • 2020-11-30 22:57

    I had the same problem with jquery ui's menu - a preventDefault() on the anchor's click event stops the page from scrolling back to the top:

     $("ul.ui-menu li a").click(function(e) {
          e.preventDefault();
     });
    
    0 讨论(0)
  • 2020-11-30 22:59

    There is a much more simple way which I discovered from the comments on this page that is to simply remove the href="#" and it will not jump to the top any more! I verified and it works for me. Cheers

    0 讨论(0)
  • 2020-11-30 22:59

    replace the href="#" with href="javascript:void(0);" in 'a' element

    works 100%

    0 讨论(0)
  • 2020-11-30 23:06

    I was given a solution for this...

    How to stop screen from jumping up when tab is clicked:

    Wrap the div that contains the tabs in a div with a fixed height.

    See example here: http://5bosses.com/examples/tabs/sample_tabs.html

    0 讨论(0)
  • 2020-11-30 23:07

    I prefer to have an href="#" in my links that do not take the user anywhere, but you can do this as long as you add an onclick="return false;". The key, I guess, is not sending the user to "#", which depending on the browser seems to default as the top of the current page.

    0 讨论(0)
  • 2020-11-30 23:07

    I had such a problem. My code was:

    $("#tabs").tabs({
      hide: {
        effect: "fade",
        duration: "500"
      },
      show: {
        effect: "fade",
        duration: "500"
      }
    });
    

    I have simply removed show and it worked like a charm!

     $("#tabs").tabs({
          hide: {
            effect: "fade",
            duration: "500"
          }
     });
    
    0 讨论(0)
提交回复
热议问题