Skip to content

Commit 57e68fc

Browse files
committed
sweaks: remove the 'scrollContent' component
1 parent ef145f8 commit 57e68fc

File tree

5 files changed

+91
-125
lines changed

5 files changed

+91
-125
lines changed

demo.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<div id="app" >
3030
<div class="scroll">
3131
<vue-scroll
32-
:scroll-content-style="{height:'100%'}"
32+
3333
:ops="ops"
3434
@hscroll="detectHBar"
3535
@vscroll="detectVBar"

docs/index.html

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ <h2>Vuescroll Demo</h2>
113113
</v-flex>
114114
<v-flex md4 xs12 >
115115
<v-card dark color="purple">
116-
<v-card-media height="200px" :style="{width: windowInnerwidh}">
116+
<v-card-media height="200px" :style="{width: windowInnerwidh}" >
117117
<vue-scroll
118118
:ops="demo1"
119119
>
@@ -133,7 +133,7 @@ <h2>Vuescroll Demo</h2>
133133
</v-flex>
134134
<v-flex md4 xs12 >
135135
<v-card dark color="purple">
136-
<v-card-media height="200px" :style="{width: windowInnerwidh}">
136+
<v-card-media height="200px" :style="{width: windowInnerwidh}" >
137137
<vue-scroll
138138
:ops="demo2"
139139
>
@@ -153,7 +153,7 @@ <h2>Vuescroll Demo</h2>
153153
</v-flex>
154154
<v-flex md4 xs12 >
155155
<v-card dark color="purple">
156-
<v-card-media height="200px" :style="{width: windowInnerwidh}">
156+
<v-card-media height="200px" :style="{width: windowInnerwidh}" >
157157
<vue-scroll
158158
:ops="demo3"
159159
>
@@ -173,7 +173,7 @@ <h2>Vuescroll Demo</h2>
173173
</v-flex>
174174
<v-flex md4 xs12 >
175175
<v-card dark color="purple">
176-
<v-card-media height="200px" :style="{width: windowInnerwidh}">
176+
<v-card-media height="200px" :style="{width: windowInnerwidh}" >
177177
<vue-scroll
178178
:ops="demo4"
179179
>
@@ -193,7 +193,7 @@ <h2>Vuescroll Demo</h2>
193193
</v-flex>
194194
<v-flex md4 xs12 >
195195
<v-card dark color="purple">
196-
<v-card-media height="200px" :style="{width: windowInnerwidh}">
196+
<v-card-media height="200px" :style="{width: windowInnerwidh}" >
197197
<vue-scroll
198198
:ops="demo5"
199199
>
@@ -213,7 +213,7 @@ <h2>Vuescroll Demo</h2>
213213
</v-flex>
214214
<v-flex md4 xs12 >
215215
<v-card dark color="purple">
216-
<v-card-media height="200px" :style="{width: windowInnerwidh}">
216+
<v-card-media height="200px" :style="{width: windowInnerwidh}" >
217217
<vue-scroll
218218
:ops="demo6"
219219
>
@@ -233,7 +233,7 @@ <h2>Vuescroll Demo</h2>
233233
</v-flex>
234234
<v-flex md4 xs12 >
235235
<v-card dark color="purple">
236-
<v-card-media height="200px" :style="{width: windowInnerwidh}">
236+
<v-card-media height="200px" :style="{width: windowInnerwidh}" >
237237
<vue-scroll
238238
:ops="demo7"
239239
>
@@ -253,7 +253,7 @@ <h2>Vuescroll Demo</h2>
253253
</v-flex>
254254
<v-flex md4 xs12 >
255255
<v-card dark color="purple">
256-
<v-card-media height="200px" :style="{width: windowInnerwidh}">
256+
<v-card-media height="200px" :style="{width: windowInnerwidh}" >
257257
<vue-scroll
258258
:ops="demo8"
259259
>
@@ -273,7 +273,7 @@ <h2>Vuescroll Demo</h2>
273273
</v-flex>
274274
<v-flex md4 xs12 >
275275
<v-card dark color="purple">
276-
<v-card-media height="200px" :style="{width: windowInnerwidh}">
276+
<v-card-media height="200px" :style="{width: windowInnerwidh}" >
277277
<vue-scroll
278278
:ops="demo9"
279279
>
@@ -293,7 +293,7 @@ <h2>Vuescroll Demo</h2>
293293
</v-flex>
294294
<v-flex md4 xs12 >
295295
<v-card dark color="purple">
296-
<v-card-media height="200px" :style="{width: windowInnerwidh}">
296+
<v-card-media height="200px" :style="{width: windowInnerwidh}" >
297297
<vue-scroll
298298
:ops="demo10"
299299
@hscroll="hscroll"
@@ -316,7 +316,7 @@ <h2>Vuescroll Demo</h2>
316316
</v-flex>
317317
<v-flex md4 xs12 >
318318
<v-card dark color="purple">
319-
<v-card-media height="200px" :style="{width: windowInnerwidh}">
319+
<v-card-media height="200px" :style="{width: windowInnerwidh}" >
320320
<vue-scroll
321321
:ops="demo11"
322322
@vscroll="vscroll"
@@ -339,7 +339,7 @@ <h2>Vuescroll Demo</h2>
339339
</v-flex>
340340
<v-flex md4 xs12 >
341341
<v-card dark color="purple">
342-
<v-card-media height="200px" :style="{width: windowInnerwidh}">
342+
<v-card-media height="200px" :style="{width: windowInnerwidh}" >
343343
<vue-scroll
344344
:ops="demo12"
345345
>
@@ -359,7 +359,7 @@ <h2>Vuescroll Demo</h2>
359359
</v-flex>
360360
<v-flex md4 xs12 >
361361
<v-card dark color="purple">
362-
<v-card-media height="200px" :style="{width: windowInnerwidh}">
362+
<v-card-media height="200px" :style="{width: windowInnerwidh}" >
363363
<vue-scroll
364364
:ops="demo13"
365365
>
@@ -379,7 +379,7 @@ <h2>Vuescroll Demo</h2>
379379
</v-flex>
380380
<v-flex md4 xs12 >
381381
<v-card dark color="purple">
382-
<v-card-media height="200px" :style="{width: windowInnerwidh}">
382+
<v-card-media height="200px" :style="{width: windowInnerwidh}" >
383383
<vue-scroll
384384
:ops="demo14"
385385
>
@@ -399,7 +399,7 @@ <h2>Vuescroll Demo</h2>
399399
</v-flex>
400400
<v-flex md4 xs12 >
401401
<v-card dark color="purple">
402-
<v-card-media height="200px" :style="{width: windowInnerwidh}">
402+
<v-card-media height="200px" :style="{width: windowInnerwidh}" >
403403
<vue-scroll
404404
:ops="demo15"
405405
>

docs/vuescroll.js

Lines changed: 37 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
11
/*
2-
* name: vuescroll 2.7.0
2+
* name: vuescroll 2.7.1
33
* author: wangyi
4-
* update date: 22 Jan. 2018
54
* description: A virtual scrollbar bar based on vue.js 2.0 inspired by slimscroll
65
* license: MIT
76
*/
87
(function(global, factory) {
98
typeof define === 'function' && define.amd ? define(factory) : typeof module !== 'undefined' ? module.exports = factory() : (global.Vue.use(factory()));
109
}
1110
)(this, function() {
11+
/**
12+
* @description return the computed value of a dom
13+
* @author wangyi7099
14+
* @param {any} dom
15+
* @param {any} property
16+
*/
17+
function getComputed(dom, property) {
18+
return window.getComputedStyle(dom).getPropertyValue(property);
19+
}
20+
21+
1222

1323
var scroll = {
1424
install: function(Vue) {
1525
Vue.component(vScrollBar.name, vScrollBar);
1626
Vue.component(hScrollBar.name, hScrollBar);
1727
Vue.component(vueScrollPanel.name, vueScrollPanel);
18-
Vue.component(vueScrollCon.name, vueScrollCon);
1928
//vueScroll
2029
Vue.component(vueScroll.name, vueScroll);
2130
}
@@ -25,12 +34,10 @@
2534
name: 'vueScrollPanel',
2635
render: function(createElement) {
2736
var vm = this;
37+
var style = vm.scrollContentStyle;
38+
style.overflow = 'hidden';
2839
return createElement('div', {
29-
style: {
30-
width: '100%',
31-
height: '100%',
32-
overflow: 'hidden'
33-
},
40+
style: style,
3441
class: "vueScrollPanel",
3542
on: {
3643
mouseenter: function() {
@@ -45,28 +52,13 @@
4552
props: {
4653
id: {
4754
require: true
48-
}
49-
}
50-
}
51-
var vueScrollCon = {
52-
name: 'vueScrollCon',
53-
render: function(createElement) {
54-
var vm = this;
55-
// console.log(this)
56-
return createElement('div', {
57-
style: vm.scrollContentStyle,
58-
class: "vueScrollContent",
59-
}, this.$slots.default);
60-
},
61-
props: {
55+
},
6256
scrollContentStyle: {
63-
require: false,
64-
default: {
65-
height: '100%'
66-
}
57+
6758
}
6859
}
6960
}
61+
7062

7163
// vertical scrollBar
7264
var vScrollBar = {
@@ -188,11 +180,6 @@
188180
ops: {
189181
}
190182
},
191-
scrollContent: {
192-
el: "",
193-
ops: {
194-
}
195-
},
196183
vScrollBar: {
197184
el: "",
198185
ops: {
@@ -231,7 +218,6 @@
231218
},
232219
listeners: [],
233220
mousedown: false,
234-
beginTouch: false,
235221
isMouseLeavePanel: true
236222
}
237223
},
@@ -259,13 +245,11 @@
259245
on: {
260246
showBar: vm.showBar,
261247
hideBar: vm.hideBar
262-
}
263-
}, [createElement('vueScrollCon', {
264-
props: {
265-
scrollContentStyle: vm.scrollContent.ops
266248
},
267-
ref: 'vueScrollCon'
268-
}, vm.$slots.default)]), createElement('vScrollBar', {
249+
props: {
250+
scrollContentStyle: vm.scrollContentStyle
251+
}
252+
}, vm.$slots.default), createElement('vScrollBar', {
269253
props: {
270254
ops: vm.vScrollBar.ops,
271255
state: vm.vScrollBar.state
@@ -292,21 +276,19 @@
292276
this.mergeAll();
293277
this.listenVBarDrag();
294278
this.listenHBarDrag();
295-
this.listenContentTouch();
279+
this.listenPanelTouch();
296280
// showbar at init time
297281
this.showBar();
298282
},
299283
methods: {
300284
initEl() {
301285
this.scrollPanel.el = this.$refs['vueScrollPanel'] && this.$refs['vueScrollPanel'].$el;
302-
this.scrollContent.el = this.$refs['vueScrollCon'] && this.$refs['vueScrollCon'].$el;
303286
this.vScrollBar.el = this.$refs['vScrollBar'] && this.$refs['vScrollBar'].$el;
304287
this.hScrollBar.el = this.$refs['hScrollBar'] && this.$refs['hScrollBar'].$el;
305288
},
306289
mergeAll() {
307290
this.merge(this.ops.vBar, this.vScrollBar.ops);
308291
this.merge(this.ops.hBar, this.hScrollBar.ops);
309-
this.merge(this.scrollContentStyle, this.scrollContent.ops, false);
310292
},
311293
merge(from, to, check) {
312294
for (key in from) {
@@ -319,7 +301,7 @@
319301
},
320302
// get the bar height
321303
getVBarHeight({deltaY}) {
322-
var scrollPanelHeight = Math.floor(window.getComputedStyle(this.scrollPanel.el).getPropertyValue("height").replace('px', ""));
304+
var scrollPanelHeight = Math.floor(getComputed(this.scrollPanel.el, "height").replace('px', ""));
323305
var scrollPanelScrollHeight = Math.floor(this.scrollPanel.el.scrollHeight);
324306
// the last times that vertical scrollvar will scroll...
325307
var scrollTime = Math.ceil((scrollPanelScrollHeight - scrollPanelHeight) / Math.abs(deltaY));
@@ -339,7 +321,7 @@
339321
}
340322
},
341323
getHBarWidth({deltaX}) {
342-
var scrollPanelWidth = Math.floor(window.getComputedStyle(this.scrollPanel.el).getPropertyValue("width").replace('px', ""));
324+
var scrollPanelWidth = Math.floor(getComputed(this.scrollPanel.el, 'width').replace('px', ""));
343325
var scrollPanelScrollWidth = Math.floor(this.scrollPanel.el.scrollWidth);
344326
// the last times that horizontal scrollbar will scroll...
345327
var scrollTime = Math.ceil((scrollPanelScrollWidth - scrollPanelWidth) / Math.abs(deltaX));
@@ -443,7 +425,7 @@
443425
// >0 scroll to down <0 scroll to up
444426

445427
var top = this.vScrollBar.state.top;
446-
var scrollPanelHeight = window.getComputedStyle(this.scrollPanel.el).getPropertyValue("height").replace('px', "");
428+
var scrollPanelHeight = getComputed(this.scrollPanel.el, 'height').replace('px', "");
447429
var scrollPanelScrollHeight = this.scrollPanel.el.scrollHeight;
448430
var scrollPanelScrollTop = this.scrollPanel.el.scrollTop;
449431
var height = this.vScrollBar.state.height;
@@ -479,7 +461,7 @@
479461
// >0 scroll to right <0 scroll to left
480462

481463
var left = this.hScrollBar.state.left;
482-
var scrollPanelWidth = window.getComputedStyle(this.scrollPanel.el).getPropertyValue("width").replace('px', "");
464+
var scrollPanelWidth = getComputed(this.scrollPanel.el, 'width').replace('px', "");
483465
var scrollPanelScrollWidth = this.scrollPanel.el.scrollWidth;
484466
var scrollPanelScrollLeft = this.scrollPanel.el.scrollLeft;
485467
var width = this.hScrollBar.state.width;
@@ -579,9 +561,9 @@
579561
});
580562
vm.hScrollBar.el.addEventListener('mousedown', t);
581563
},
582-
listenContentTouch: function() {
564+
listenPanelTouch: function() {
583565
var vm = this;
584-
var content = this.scrollContent.el;
566+
var pannel = this.scrollPanel.el;
585567
var x, y;
586568
var _x, _y;
587569
function move(e) {
@@ -620,17 +602,17 @@
620602
x = touch.pageX;
621603
y = touch.pageY;
622604
vm.showBar();
623-
content.addEventListener('touchmove', move);
624-
content.addEventListener('touchend', function(e) {
605+
pannel.addEventListener('touchmove', move);
606+
pannel.addEventListener('touchend', function(e) {
625607
vm.mousedown = false;
626608
vm.hideBar();
627-
content.removeEventListener('touchmove', move);
609+
pannel.removeEventListener('touchmove', move);
628610
});
629611
}
630612
}
631-
content.addEventListener('touchstart', t);
613+
pannel.addEventListener('touchstart', t);
632614
this.listeners.push({
633-
dom: content,
615+
dom: pannel,
634616
event: t,
635617
type: "touchstart"
636618
});
@@ -658,7 +640,8 @@
658640
scrollContentStyle: {
659641
default:function () {
660642
return {
661-
643+
width: '100%',
644+
height: '100%'
662645
}
663646
}
664647
},
@@ -671,4 +654,4 @@
671654
function noop() {}
672655

673656
return scroll;
674-
});
657+
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,5 @@
5252
"scripts": {
5353
"test": "echo \"Error: no test specified\" && exit 1"
5454
},
55-
"version": "2.7.0"
55+
"version": "2.7.1"
5656
}

0 commit comments

Comments
 (0)