jQuery scrollTop() does not work in scrolling DIV on mobile browsers, alternatives?

前端 未结 13 1025
傲寒
傲寒 2020-12-08 19:52

I am trying to scroll to a specific location in a scrolling DIV. Right now I am using a pixel offset with the jQuery scrollTop() function which works great on desktop brows

13条回答
  •  长情又很酷
    2020-12-08 20:03

    I have a couple solutions for you to try. You will have to test them yourself, as I have not tried them in a mobile browser before, but here they are:

    1. Use jQuery's .css() method (or .animate() depending on what your eventual goal us) to adjust the top margin (note: you would have to change the overflow to hidden and wrap the text in an inner div, which would be the element whose to margin you are adjusting)
    2. Do the same thing as in the first solution, except set the embedded div's position to relative and adjust it's top attribute.

    Let me know if you need help with any if this or have any more questions about this. Good luck! :)


    Note that although I have not tested these in mobile before they are based on CSS standards, not jQuery functions, so they should work.

提交回复
热议问题