├── .gitignore ├── .npmignore ├── History.md ├── Makefile ├── Readme.md ├── example.html ├── index.es6 └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.js 3 | node_modules -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.es6 3 | -------------------------------------------------------------------------------- /History.md: -------------------------------------------------------------------------------- 1 | 2 | 1.0.2 / 2015-01-15 3 | ================== 4 | 5 | * Remove extraneous test code. 6 | 7 | 1.0.1 / 2015-01-15 8 | ================== 9 | 10 | * Stop DOM tree ascension at document.body (Fixes scrolling bug under some circumstances) 11 | 12 | 1.0.0 / 2015-01-15 13 | ================== 14 | 15 | * Fix npm publish loop in Makefile. 16 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Get Makefile directory name: http://stackoverflow.com/a/5982798/376773. 2 | # This is a defensive programming approach to ensure that this Makefile 3 | # works even when invoked with the `-C`/`--directory` option. 4 | THIS_MAKEFILE_PATH:=$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)) 5 | THIS_DIR:=$(shell cd $(dir $(THIS_MAKEFILE_PATH));pwd) 6 | 7 | # BIN directory 8 | BIN := $(THIS_DIR)/node_modules/.bin 9 | NODE ?= node 10 | SIX_TO_FIVE ?= $(NODE) $(BIN)/6to5 11 | BROWSERIFY ?= $(NODE) $(BIN)/browserify 12 | 13 | ES6_FILES := $(wildcard *.es6) 14 | JS_FILES := $(wildcard *.js) 15 | 16 | COMPILED_FILES := $(ES6_FILES:.es6=.js) 17 | 18 | build: install $(COMPILED_FILES) 19 | 20 | install: node_modules 21 | 22 | example: build 23 | $(BROWSERIFY) index.js -s example -o example.js 24 | 25 | clean: $(COMPILED_FILES) 26 | rm $(COMPILED_FILES) 27 | 28 | node_modules: 29 | npm install 30 | 31 | %.js: %.es6 32 | $(SIX_TO_FIVE) -i coreAliasing $< --out-file $@ 33 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # element-scroll-to 2 | 3 | Makes sure an element is fully visible on the browser viewport, 4 | by recursively scrolling all elements that might be containing it, 5 | along with the browser window. 6 | 7 | If scrolling the entirety of the element into the viewport is not 8 | possible (e.g. it's larger than the viewport, or positioned outside 9 | of the page) a best effort is made to position it on the viewport. 10 | 11 | If the supplied element is `position: fixed` or `position: sticky`, 12 | the behavior is undefined. 13 | 14 | ## Usage 15 | 16 | ```js 17 | var scrollTo = require('element-scroll-to'); 18 | 19 | // ... 20 | 21 | scrollTo(element, options); 22 | ``` 23 | 24 | options may include: 25 | 26 | - `margin` (default 0): additional gutters around the element 27 | 28 | ## License 29 | 30 | The MIT License (MIT) 31 | 32 | Copyright (c) 2015 Automattic Inc. 33 | 34 | Permission is hereby granted, free of charge, to any person obtaining a copy 35 | of this software and associated documentation files (the "Software"), to deal 36 | in the Software without restriction, including without limitation the rights 37 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 38 | copies of the Software, and to permit persons to whom the Software is 39 | furnished to do so, subject to the following conditions: 40 | 41 | The above copyright notice and this permission notice shall be included in 42 | all copies or substantial portions of the Software. 43 | 44 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 45 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 46 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 47 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 48 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 49 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 50 | THE SOFTWARE. 51 | -------------------------------------------------------------------------------- /example.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |