MCPcopy
hub / github.com/jabbany/CommentCoreLibrary / CssScrollComment

Class CssScrollComment

src/core/css-renderer/CssComment.ts:21–90  ·  view source on GitHub ↗

* An add-in class to support CSS-based scrolling comments

Source from the content-addressed store, hash-verified

19 * An add-in class to support CSS-based scrolling comments
20 */
21class CssScrollComment extends ScrollComment {
22 // Marker for whether we need to re-create the CSS or not
23 private _dirtyCSS:boolean = true;
24
25 public init(recycle:IComment = null):void {
26 super.init(recycle);
27 this._toggleClass('css-optimize', true);
28 }
29
30 set x(x:number) {
31 if (this._x !== null && typeof this._x === "number") {
32 // This is run when starting
33 var dx:number = x - this._x;
34 this._x = x;
35 CssCompatLayer.transform(this.dom, "translateX(" +
36 (this.axis % 2 === 0 ? dx : -dx) + "px)");
37 } else {
38 // This is run when stopping
39 this._x = x;
40 if (!this.absolute) {
41 this._x *= this.parent.width;
42 }
43 // Got the x-value, now figure out where things are
44 if (this.axis % 2 === 0) {
45 // x-axis towards right
46 this.dom.style.left =
47 (this._x + (this.align % 2 === 0 ? 0 : -this.width)) + 'px';
48 } else {
49 // x-axis towards left
50 this.dom.style.right =
51 (this._x + (this.align % 2 === 0 ? -this.width : 0)) + 'px';
52 }
53 }
54 }
55
56 get x():number{
57 // X always goes from {parent.width to -this.width}
58 return (this.ttl / this.dur) * (this.parent.width + this.width) - this.width;
59 }
60
61 public update():void{
62 if (this._dirtyCSS) {
63 // Start moving
64 this.dom.style.transition = "transform " + this.ttl + "ms linear";
65 this.x = - this.width;
66 this._dirtyCSS = false;
67 }
68 }
69
70 public invalidate():void{
71 super.invalidate();
72 this._dirtyCSS = true;
73 }
74
75 /**
76 * Override the toplevel stop to actually stop the CSS.
77 */
78 public stop():void{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected