Utils: scroll-into-view should consider target element's offset parents (#11058)

This commit is contained in:
杨奕 2018-05-08 15:50:55 +08:00 committed by GitHub
parent 71a66ae21d
commit ea70cf5a01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 4 deletions

View File

@ -36,7 +36,7 @@ if [ "$TRAVIS_TAG" ]; then
# build site # build site
npm run deploy:build npm run deploy:build
cd temp_web cd temp_web
git clone -b gh-pages https://$ROT_TOKEN@github.com/ElemeFE/element.git && cd element git clone --depth 1 -b gh-pages --single-branch https://$ROT_TOKEN@github.com/ElemeFE/element.git && cd element
# build sub folder # build sub folder
echo $TRAVIS_TAG echo $TRAVIS_TAG

View File

@ -2,7 +2,7 @@
mkdir temp_web mkdir temp_web
npm run deploy:build npm run deploy:build
cd temp_web cd temp_web
git clone -b gh-pages https://github.com/ElemeFE/element.git && cd element git clone --depth 1 -b gh-pages --single-branch https://github.com/ElemeFE/element.git && cd element
# build sub folder # build sub folder
SUB_FOLDER='2.3' SUB_FOLDER='2.3'

View File

@ -8,8 +8,14 @@ export default function scrollIntoView(container, selected) {
return; return;
} }
const top = selected.offsetTop; const offsetParents = [];
const bottom = selected.offsetTop + selected.offsetHeight; let pointer = selected.offsetParent;
while (pointer && container !== pointer && container.contains(pointer)) {
offsetParents.push(pointer);
pointer = pointer.offsetParent;
}
const top = selected.offsetTop + offsetParents.reduce((prev, curr) => (prev + curr.offsetTop), 0);
const bottom = top + selected.offsetHeight;
const viewRectTop = container.scrollTop; const viewRectTop = container.scrollTop;
const viewRectBottom = viewRectTop + container.clientHeight; const viewRectBottom = viewRectTop + container.clientHeight;