Skip to content

Commit 6b44a6f

Browse files
authored
Merge pull request #235 from ianhi/capture-scroll
Add option to preventDefault on scroll event
2 parents 7dabbff + c0c1004 commit 6b44a6f

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

examples/ipympl.ipynb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@
6565
"fig.canvas.resizable = False"
6666
]
6767
},
68+
{
69+
"cell_type": "code",
70+
"execution_count": null,
71+
"metadata": {},
72+
"outputs": [],
73+
"source": [
74+
"fig.canvas.capture_scroll = True"
75+
]
76+
},
6877
{
6978
"cell_type": "code",
7079
"execution_count": null,

ipympl/backend_nbagg.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ class Canvas(DOMWidget, FigureCanvasWebAggCore):
175175
footer_visible = Bool(True).tag(sync=True)
176176

177177
resizable = Bool(True).tag(sync=True)
178+
capture_scroll = Bool(False).tag(sync=True)
178179

179180
_width = CInt().tag(sync=True)
180181
_height = CInt().tag(sync=True)

js/src/mpl_widget.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export class MPLCanvasModel extends widgets.DOMWidgetModel {
2121
toolbar_visible: true,
2222
toolbar_position: 'horizontal',
2323
resizable: true,
24+
capture_scroll: false,
2425
_width: 0,
2526
_height: 0,
2627
_figure_label: 'Figure',
@@ -565,6 +566,9 @@ export class MPLCanvasView extends widgets.DOMWidgetView {
565566
} else {
566567
event.step = -1;
567568
}
569+
if (this.model.get('capture_scroll')) {
570+
event.preventDefault();
571+
}
568572
}
569573

570574
if (name === 'button_press') {

0 commit comments

Comments
 (0)