[removed] Scroll to selection after using textarea.setSelectionRange in Chrome

前端 未结 8 596
离开以前
离开以前 2020-12-31 05:05

A javascript function selects a certain word in a textarea using .setSelectionRange(). In Firefox, the textarea automatically scrolls down to show the selected text. In Chro

8条回答
  •  粉色の甜心
    2020-12-31 05:35

    I published an answer here:

    http://blog.blupixelit.eu/scroll-textarea-to-selected-word-using-javascript-jquery/

    It works perfectly with jsut one needed rule: Set a line-height n the css of the textarea!

    It calculate the position of the word to scroll to just by doing some simple mathematic calculation and it worked perfectly in all my experiments!

    Feel free to ask me anything you need about the code!

提交回复
热议问题