How to scroll to an element in jQuery?

后端 未结 9 1702
无人及你
无人及你 2020-11-30 19:23

I have done the following code in JavaScript to put focus on the particular element (branch1 is a element),

document.location.href=\"#branch1\";
         


        
9条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-30 19:48

    For the focus() function to work on the element the div needs to have a tabindex attribute. This is probably not done by default on this type of element as it is not an input field. You can add a tabindex for example at -1 to prevent users who use tab to focus on it. If you use a positive tabindex users will be able to use tab to focus on the div element.

    Here an example: http://jsfiddle.net/klodder/gFPQL/

    However tabindex is not supported in Safari.

提交回复
热议问题