OLD | NEW |
---|---|
(Empty) | |
1 <polymer-element name="viewer-page-indicator" attributes="text"> | |
2 <template> | |
3 <link rel="stylesheet" href="viewer-page-indicator.css"> | |
4 <div id="text">1</div> | |
ganetsky1
2014/02/04 17:27:29
You can use data binding
http://www.polymer-proje
raymes
2014/02/05 05:04:37
Oops. Done.
| |
5 <div id="triangle-right"></div> | |
6 </template> | |
7 <script> | |
8 Polymer('viewer-page-indicator', { | |
9 text: '1', | |
10 timerId: undefined, | |
11 ready: function() { | |
12 var scrollCallback = function() { | |
13 if (document.documentElement.clientWidth == window.innerWidth) | |
14 this.style.visibility = 'hidden'; | |
15 else | |
16 this.style.visibility = 'visible'; | |
ganetsky1
2014/02/04 17:27:29
Ternary operator?
this.style.visibility = (docume
raymes
2014/02/05 05:04:37
Done.
| |
17 | |
18 var percent = window.scrollY / | |
19 (document.body.scrollHeight - | |
20 document.documentElement.clientHeight); | |
ganetsky1
2014/02/04 17:27:29
Fix indentation
raymes
2014/02/05 05:04:37
Done.
| |
21 this.style.top = percent * (document.documentElement.clientHeight - | |
22 this.offsetHeight) + 'px'; | |
ganetsky1
2014/02/04 17:27:29
I'd rather the entire parenthesized subexpression
raymes
2014/02/05 05:04:37
Done.
| |
23 this.style.opacity = 1; | |
24 if (this.timerId !== undefined) | |
25 clearTimeout(this.timerId); | |
ganetsky1
2014/02/04 17:27:29
nitpick: you drop the if statement and just say cl
raymes
2014/02/05 05:04:37
Done.
| |
26 | |
27 this.timerId = setTimeout(function() { | |
28 this.style.opacity = 0; | |
29 }.bind(this), 2000); | |
30 }.bind(this); | |
31 window.addEventListener('scroll', function() { | |
ganetsky1
2014/02/04 17:27:29
Can you use declarative event mapping?
http://www.
raymes
2014/02/05 05:04:37
It doesn't seem so. I guess because the scroll eve
| |
32 webkitRequestAnimationFrame(scrollCallback); | |
ganetsky1
2014/02/04 17:27:29
I don't know what the status of "webkit" prefixed
raymes
2014/02/05 05:04:37
Done. - the prefix isn't needed anymore.
| |
33 }); | |
34 | |
35 scrollCallback(); | |
36 }, | |
37 textChanged: function() { | |
38 this.$.text.innerHTML = this.text; | |
ganetsky1
2014/02/04 17:27:29
Use data binding instead
raymes
2014/02/05 05:04:37
Done.
| |
39 }, | |
40 }); | |
41 </script> | |
42 </polymer-element> | |
OLD | NEW |