-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsticky-element.html
86 lines (75 loc) · 1.88 KB
/
sticky-element.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<link rel="import" href="../polymer/polymer-element.html">
<dom-module id="sticky-element">
<template>
<style>
:host {
position: -webkit-sticky;
position: sticky;
top: 0.5rem;
}
</style>
<slot></slot>
</template>
<script src="../Stickyfill/dist/stickyfill.min.js"></script>
<script>
/**
* `sticky-element` Description
*
* @summary ShortDescription.
* @customElement
* @polymer
* @extends {Polymer.Element}
*/
class StickyElement extends Polymer.Element {
/**
* String providing the tag name to register the element under.
*/
static get is() {
return 'sticky-element';
}
/**
* Object describing property-related metadata used by Polymer features
*/
static get properties() {
return {
disabled: {
type: Boolean,
observer: '_disabledChanged'
}
};
}
/**
* Instance of the element is created/upgraded. Use: initializing state,
* set up event listeners, create shadow dom.
* @constructor
*/
constructor() {
super();
}
/**
* Use for one-time configuration of your component after local DOM is initialized.
*/
ready() {
super.ready();
Polymer.RenderStatus.afterNextRender(this, function() {
if (!this.disabled) {
this._updateSticky(true);
Stickyfill.rebuild();
}
});
}
_updateSticky (sticky) {
if (sticky) {
Stickyfill.add(this);
} else {
Stickyfill.remove(this);
}
Stickyfill.rebuild();
}
_disabledChanged (disabled) {
this._updateSticky(!disabled)
}
}
window.customElements.define(StickyElement.is, StickyElement);
</script>
</dom-module>