Skip to content
This repository was archived by the owner on Jul 29, 2019. It is now read-only.

Commit 0545f38

Browse files
yotamberkmojoaxel
authored andcommitted
Fixes #2295 Issues with vertical scroll and maxHeight (#2302)
* Fixes #2273 * Remove console.log * Fix for zoomable false * Fix initial scrolling with verticalScroll and fix example
1 parent a29aae9 commit 0545f38

File tree

3 files changed

+24
-23
lines changed

3 files changed

+24
-23
lines changed

examples/timeline/other/verticalScroll.html

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,13 @@ <h2>With <code>
5252
date.setHours(date.getHours() + 2 + Math.floor(Math.random()*4));
5353
var end = new Date(date);
5454

55+
var orderIndex = order + itemsPerGroup * truck
5556
items.add({
56-
id: order + itemsPerGroup * truck,
57+
id: orderIndex,
5758
group: truck,
5859
start: start,
5960
end: end,
60-
content: 'Order ' + order
61+
content: 'Order ' + orderIndex
6162
});
6263
}
6364
}
@@ -70,15 +71,10 @@ <h2>With <code>
7071
maxHeight: 200,
7172
start: new Date(),
7273
end: new Date(1000*60*60*24 + (new Date()).valueOf()),
73-
editable: true,
74-
margin: {
75-
item: 10, // minimal margin between items
76-
axis: 5 // minimal margin between items and the axis
77-
},
78-
orientation: 'top'
7974
};
8075

8176
// create a Timeline
77+
8278
options1 = Object.assign({}, options)
8379
var container1 = document.getElementById('mytimeline1');
8480
timeline1 = new vis.Timeline(container1, items, groups, options1);

lib/timeline/Core.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,15 @@ Core.prototype._create = function (container) {
174174
this.emit('mousewheel', event);
175175
}
176176

177+
// prevent scrolling if not specified explicitly or when horizontalScroll is true
178+
if (!this.options.verticalScroll || this.options.horizontalScroll) return;
179+
177180
// prevent scrolling when zoomKey defined or activated
178-
if (!this.options.zoomKey || event[this.options.zoomKey]) return
181+
if (!this.options.zoomKey || event[this.options.zoomKey]) return;
179182

180-
// prevent scrolling vertically when horizontalScroll is true
181-
if (this.options.horizontalScroll) return
183+
// Prevent default actions caused by mouse wheel
184+
// (else the page and timeline both scroll)
185+
event.preventDefault();
182186

183187
var delta = 0;
184188
if (event.wheelDelta) { /* IE/Opera. */
@@ -194,17 +198,9 @@ Core.prototype._create = function (container) {
194198

195199
if (this.isActive()) {
196200
this._setScrollTop(adjusted);
197-
if (this.options.verticalScroll) {
198-
this.dom.left.parentNode.scrollTop = -adjusted;
199-
this.dom.right.parentNode.scrollTop = -adjusted;
200-
}
201201
this._redraw();
202202
this.emit('scroll', event);
203203
}
204-
205-
// Prevent default actions caused by mouse wheel
206-
// (else the page and timeline both scroll)
207-
event.preventDefault();
208204
}
209205

210206
if (this.dom.centerContainer.addEventListener) {
@@ -1204,6 +1200,11 @@ Core.prototype._updateScrollTop = function () {
12041200
if (this.props.scrollTop > 0) this.props.scrollTop = 0;
12051201
if (this.props.scrollTop < scrollTopMin) this.props.scrollTop = scrollTopMin;
12061202

1203+
if (this.options.verticalScroll) {
1204+
this.dom.left.parentNode.scrollTop = -this.props.scrollTop;
1205+
this.dom.right.parentNode.scrollTop = -this.props.scrollTop;
1206+
}
1207+
12071208
return this.props.scrollTop;
12081209
};
12091210

lib/timeline/Range.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -488,10 +488,6 @@ Range.prototype._onDragEnd = function (event) {
488488
* @private
489489
*/
490490
Range.prototype._onMouseWheel = function(event) {
491-
// Prevent default actions caused by mouse wheel
492-
// (else the page and timeline both zoom and scroll)
493-
event.preventDefault();
494-
495491
// retrieve delta
496492
var delta = 0;
497493
if (event.wheelDelta) { /* IE/Opera. */
@@ -506,6 +502,10 @@ Range.prototype._onMouseWheel = function(event) {
506502
if ((this.options.zoomKey && !event[this.options.zoomKey] && this.options.zoomable)
507503
|| (!this.options.zoomable && this.options.moveable)) {
508504
if (this.options.horizontalScroll) {
505+
// Prevent default actions caused by mouse wheel
506+
// (else the page and timeline both scroll)
507+
event.preventDefault();
508+
509509
// calculate a single scroll jump relative to the range scale
510510
var diff = delta * (this.end - this.start) / 20;
511511
// calculate new start and end
@@ -544,6 +544,10 @@ Range.prototype._onMouseWheel = function(event) {
544544
var pointerDate = this._pointerToDate(pointer);
545545

546546
this.zoom(scale, pointerDate, delta);
547+
548+
// Prevent default actions caused by mouse wheel
549+
// (else the page and timeline both scroll)
550+
event.preventDefault();
547551
}
548552
};
549553

0 commit comments

Comments
 (0)