Merge pull request 'Mouse wheel scrolling' (#7) from mouse-scrolling into master

Reviewed-on: om/chatcontrol-live-demo#7
This commit is contained in:
om 2022-08-22 05:21:29 +00:00
commit 56f1e2f9a4

View file

@ -130,6 +130,7 @@ function TextChatMessage(message_text, is_myself) {
'fill': text_color, 'fill': text_color,
'width': '5%' 'width': '5%'
}); });
enable_scrolling(tspan)
if(is_hyperlink(line)) { if(is_hyperlink(line)) {
tspan.appendChild(create_link_node(line)); tspan.appendChild(create_link_node(line));
@ -246,6 +247,7 @@ function create_bubble(inner_element, color) {
'rx': 8, 'rx': 8,
'fill': color, 'fill': color,
}); });
enable_scrolling(bubble);
return bubble; return bubble;
} }
@ -417,6 +419,16 @@ async function scroll_down() {
current_dialog.scroll_by(-line_height); current_dialog.scroll_by(-line_height);
} }
const on_wheel = (e) => { e.deltaY < 0 ? scroll_up() : scroll_down() }
const enable_scrolling = (elem) => elem.addEventListener('wheel', on_wheel);
// enable scrolling
document.addEventListener(
"DOMContentLoaded",
() => document.getElementById("message_box").addEventListener('wheel', on_wheel)
)
async function dialog_ven() { async function dialog_ven() {
let d = new Dialog(); let d = new Dialog();
current_dialog = d; current_dialog = d;
@ -525,7 +537,7 @@ async function dialog_nabopige() {
</g> </g>
<!-- [right] messages view --> <!-- [right] messages view -->
<rect x="300" y="50" width="300" height="450" fill="white" /> <rect id="message_box" x="300" y="50" width="300" height="450" fill="white" />
<g id="messages"></g> <g id="messages"></g>
<!-- [right] message status --> <!-- [right] message status -->

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB