Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve mousewheel event callback sample #74

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions samples/utils/domevents/mousewheel/MouseWheel.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
} }

{macro main ( )}
<h3>This sample demonstrates the usage of onwheel</h3>
<h3>This sample demonstrates the usage of mosuewheel event callback</h3>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mosue -> mouse


Use the mouse wheel on the field below.
Use the mouse scroll on the div below. One mouse scroll down is -120 and one mouse scroll up is +120.
<div style="width:200px; height:200px; overflow:auto;" {on mousewheel {
fn : this.onMouseScroll,
scope : this
Expand All @@ -15,7 +15,8 @@
</div>
<br />

The last roll amount:
Below field shows the sum of scrolled value
<br/>
<span style="background-color:#e0e0d0;">
{@aria:NumberField {bind:{value:{to:"rolled",inside:data}}}/}
</span>
Expand Down
15 changes: 5 additions & 10 deletions samples/utils/domevents/mousewheel/MouseWheelScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@ Aria.tplScriptDefinition({
$classpath : "samples.utils.domevents.mousewheel.MouseWheelScript",
$implements : ["aria.core.Browser", "aria.utils.Dom"],
$prototype : {
onMouseScroll : function (event) {
var rolled = 0;
if ('wheelDelta' in event && !aria.core.Browser.isFirefox) {
rolled = event.wheelDelta;
} else { // Firefox
// The measurement units of the detail and wheelDelta properties are different.
rolled = -40 * event.detail;
}

this.$json.setValue(this.data, "rolled", rolled);
sumRolledVal : 0,
onMouseScroll : function (evt) {
this.sumRolledVal += (evt.detail) ? evt.detail * (-40) : evt.wheelDelta;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some doubts here... why are we increasing this value?

this.sumRolledVal = this.sumRolledVal > 0 ? 0 : this.sumRolledVal;
this.$json.setValue(this.data, "rolled", this.sumRolledVal);
}
}
});