Last active
September 17, 2017 13:57
-
-
Save jdanyow/f5b43de0086cddc254ce to your computer and use it in GitHub Desktop.
Aurelia Scroll Binding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<!-- bind this div's scroll position AND bind to the scroll events --> | |
<div class="container" scrolltop.bind="scrollTop" scrollleft.bind="scrollLeft" | |
scroll.trigger="handleScrollEvent($event)"> | |
<!-- just some data to scroll... nothing to see here... --> | |
<div class="content" repeat.for="y of 100"> | |
<span repeat.for="x of 100">${x}</span> | |
</div> | |
</div> | |
<!-- output the scroll position data we captured: --> | |
<div class="output"> | |
<h3>scrollTop = ${scrollTop}px</h3> | |
<h3>scrollLeft = ${scrollLeft}px</h3> | |
<h3>Events:</h3> | |
<div css="color: ${event.color}" repeat.for="event of scrollEvents"> | |
Scroll! left: ${event.left}px; top: ${event.top}px | |
</div> | |
</div> | |
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class App { | |
scrollTop = 0; | |
scrollLeft = 0; | |
scrollEvents = []; | |
handleScrollEvent(e) { | |
let info = { | |
color: '#'+Math.floor(Math.random()*16777215).toString(16), | |
left: e.target.scrollLeft, | |
top: e.target.scrollTop | |
}; | |
this.scrollEvents.splice(0, 0, info); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<title>Aurelia</title> | |
<link rel="stylesheet" href="styles.css"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
</head> | |
<body aurelia-app> | |
<h1>Loading...</h1> | |
<script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/jspm_packages/system.js"></script> | |
<script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/config.js"></script> | |
<script> | |
System.import('aurelia-bootstrapper'); | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.container { | |
position: absolute; | |
top: 0px; | |
left: 0px; | |
bottom: 0px; | |
right: 0px; | |
overflow: auto; | |
} | |
.content { | |
color: #d3d3d3 | |
} | |
.output { | |
position: absolute; | |
top: 0px; | |
left: 0px; | |
bottom: 30px; | |
right: 30px; | |
color: red; | |
overflow: hidden | |
} | |
.output > div { | |
font-size: 12px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment