File

projects/angular2-draggable/src/lib/models/size.ts

Implements

ISize

Index

Properties
Methods

Constructor

constructor(width: number, height: number)
Parameters :
Name Type Optional
width number No
height number No

Properties

Public height
Type : number
Public width
Type : number

Methods

Static copy
copy(s: Size)
Parameters :
Name Type Optional
s Size No
Returns : Size
Static getCurrent
getCurrent(el: Element)
Parameters :
Name Type Optional
el Element No
Returns : Size
set
set(s: ISize)
Parameters :
Name Type Optional
s ISize No
Returns : this
export interface ISize {
  width: number;
  height: number;
}

export class Size implements ISize {
  constructor(public width: number, public height: number) {}

  static getCurrent(el: Element) {
    let size = new Size(0, 0);

    if (window) {
      const computed = window.getComputedStyle(el);
      if (computed) {
        size.width = parseInt(computed.getPropertyValue('width'), 10);
        size.height = parseInt(computed.getPropertyValue('height'), 10);
      }
      return size;
    } else {
      console.error('Not Supported!');
      return null;
    }
  }

  static copy(s: Size) {
    return new Size(0, 0).set(s);
  }

  set(s: ISize) {
    this.width = s.width;
    this.height = s.height;
    return this;
  }
}

results matching ""

    No results matching ""