Prevent FF < 41 scrolling to bottom of page

In Firefox < 41, the selecting fakeElem.select() would cause the browser to scroll to the bottom of the page. 

By positioning fakeElem at the current scroll position, but still way out to the left, that no longer happens.
This commit is contained in:
Calvin Correli 2015-10-02 09:32:16 -04:00
parent a4c8bc5bf0
commit 5c8af54b8a

View File

@ -56,6 +56,7 @@ class ClipboardAction {
this.fakeElem = document.createElement('textarea');
this.fakeElem.style.position = 'absolute';
this.fakeElem.style.left = '-9999px';
this.fakeElem.style.top = document.body.scrollTop + 'px';
this.fakeElem.setAttribute('readonly', '');
this.fakeElem.value = this.text;
this.selectedText = this.text;