문제

I am using a textarea with a jquery select function to allow my users to quickly select the full article for easy copying. The textarea is just one row tall and has the overflow set to hidden.

Whenever I click the label for my textarea it automatically 'scrolls down' to the bottom of my page. I found that this only happens when the overflow is set to hidden and I'm assuming it 'scrolls' down to the bottom of the selected text.

See example: http://www.creepypasta.org/Untitled.webm

HTML

<label for="copy-pasta">Copy Pasta</label>
<textarea rows="1" id="copy-pasta">Multiple lines of text...</textarea>

jQuery

$("#copy-pasta").click(function () {
    $(this).select();
});

CSS

.copy-pasta textarea {      
    overflow: hidden;
    resize: none;
}
도움이 되었습니까?

해결책

  • Store the current scroll position

  • Call your copy function

  • Restore scroll position

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top