Skip to content

Commit 20254bf

Browse files
committed
Initial vue-scrollTo.
0 parents  commit 20254bf

File tree

7 files changed

+131
-0
lines changed

7 files changed

+131
-0
lines changed

.editorconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
12+
[*.md]
13+
trim_trailing_whitespace = false
14+
15+
[Makefile]
16+
indent_style = tab

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
npm-debug.log

.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
.editorconfig

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Igor Randjelovic
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# vue-scrollTo
2+
3+
[Vue.js](https://github.com/vuejs/vue) directive.
4+
Adds a directive that listens for click events and scrolls to elements.
5+
6+
## Install
7+
8+
With [npm](http://npmjs.org) do:
9+
10+
```bash
11+
$ npm install vue-scrollTo --save
12+
```
13+
14+
## Usage
15+
16+
```js
17+
var Vue = require('vue');
18+
var vueScrollTo = require('vue-scrollTo');
19+
Vue.use(vueScrollTo);
20+
```
21+
22+
```html
23+
<a href="#" v-scroll-to=".element">Scroll to .element</a>
24+
25+
<div class="element">
26+
Hi. I'm element.
27+
</div>
28+
```
29+
30+
## License
31+
32+
MIT

index.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use strict';
2+
3+
var $ = require('jquery')
4+
5+
exports.install = function(Vue) {
6+
var _ = Vue.util
7+
8+
Vue.directive('scroll-to', {
9+
bind: function() {
10+
_.on(this.el, 'click', this.handleClick.bind(this))
11+
},
12+
unbind: function() {
13+
_.off(this.el, 'click', this.handleClick)
14+
},
15+
handleClick: function(e) {
16+
e.preventDefault()
17+
var page = $('html, body')
18+
var events = 'scroll mousedown wheel DOMMouseScroll mousewheel keyup touchmove'
19+
page.on(events, function() {
20+
page.stop()
21+
});
22+
23+
page.animate({
24+
scrollTop: $(this.expression).offset().top + 'px'
25+
}, 300, function() {
26+
page.off(events)
27+
})
28+
}
29+
})
30+
}

package.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "vue-scrollTo",
3+
"version": "1.0.0",
4+
"description": "Adds a directive that listens for click events and scrolls to elements.",
5+
"main": "index.js",
6+
"keywords": [
7+
"vue",
8+
"vuejs",
9+
"directive",
10+
"scroll",
11+
"scrollto",
12+
"scroll to"
13+
],
14+
"license": "MIT",
15+
"author": {
16+
"name": "Igor Randjelovic",
17+
"email": "shout@igor-randjelovic.com",
18+
"url": "http://igor-randjelovic.com",
19+
"twitter": "https://twitter.com/igor_randj"
20+
},
21+
"repository": {
22+
"type": "git",
23+
"url": "https://github.com/rigor789/vue-scrollTo"
24+
},
25+
"dependencies": {
26+
"jquery": "^2.2.3"
27+
}
28+
}

0 commit comments

Comments
 (0)