From 176de8c53c6e13fec6b8248e17fa5c0581744c34 Mon Sep 17 00:00:00 2001 From: Joao Cunha Date: Mon, 29 Jun 2015 13:38:31 -0300 Subject: [PATCH] Adds alternative check to scrollTop --- readme.md | 78 ++++++++++++++++++++++++------------------------- src/autosize.js | 6 ++-- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/readme.md b/readme.md index 46b09a6..c34e6df 100644 --- a/readme.md +++ b/readme.md @@ -1,39 +1,39 @@ -## Summary - -Autosize is a small, stand-alone script to automatically adjust textarea height to fit text. - -#### Demo - -Full documentation and a demo can be found at [jacklmoore.com/autosize](http://jacklmoore.com/autosize) - -#### Install via NPM -```bash -npm install autosize -``` -#### Install via Bower -```bash -bower install autosize -``` - -#### Browser compatibility - -Chrome | Firefox | IE | Safari | iOS Safari | Android | Opera Mini ------- | --------|----|--------|------------|---------|------------ -yes | yes | 9 | yes | yes | 4 | ? - -#### Usage - -The autosize function accepts a single textarea element, or an array or array-like object (such as a NodeList or jQuery collection) of textarea elements. - -```javascript -// from a NodeList -autosize(document.querySelectorAll('textarea')); - -// from a single Node -autosize(document.querySelector('textarea')); - -// from a jQuery collection -autosize($('textarea')); -``` - -Released under the [MIT License](http://www.opensource.org/licenses/mit-license.php) \ No newline at end of file +## Summary + +Autosize is a small, stand-alone script to automatically adjust textarea height to fit text. + +#### Demo + +Full documentation and a demo can be found at [jacklmoore.com/autosize](http://jacklmoore.com/autosize) + +#### Install via NPM +```bash +npm install autosize +``` +#### Install via Bower +```bash +bower install autosize +``` + +#### Browser compatibility + +Chrome | Firefox | IE | Safari | iOS Safari | Android | Opera Mini | Windows Phone IE +------ | --------|----|--------|------------|---------|------------|------------------ +yes | yes | 9 | yes | yes | 4 | ? | 8.1 + +#### Usage + +The autosize function accepts a single textarea element, or an array or array-like object (such as a NodeList or jQuery collection) of textarea elements. + +```javascript +// from a NodeList +autosize(document.querySelectorAll('textarea')); + +// from a single Node +autosize(document.querySelector('textarea')); + +// from a jQuery collection +autosize($('textarea')); +``` + +Released under the [MIT License](http://www.opensource.org/licenses/mit-license.php) diff --git a/src/autosize.js b/src/autosize.js index 835c94a..8cd6938 100644 --- a/src/autosize.js +++ b/src/autosize.js @@ -47,7 +47,7 @@ function assign(ta, {setOverflowX = true, setOverflowY = true} = {}) { function update() { const startHeight = ta.style.height; - const htmlTop = document.documentElement.scrollTop; + const htmlTop = window.pageYOffset || document.documentElement.scrollTop; const bodyTop = document.body.scrollTop; const originalHeight = ta.style.height; @@ -119,7 +119,7 @@ function assign(ta, {setOverflowX = true, setOverflowY = true} = {}) { ta.addEventListener('input', update); ta.addEventListener('autosize:update', update); ta.setAttribute('data-autosize-on', true); - + if (setOverflowY) { ta.style.overflowY = 'hidden'; } @@ -173,4 +173,4 @@ if (typeof window === 'undefined' || typeof window.getComputedStyle !== 'functio }; } -export default autosize; \ No newline at end of file +export default autosize;