sticky.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { position, place_top } from "./position.js";
  2. import { size, auto } from "./size.js";
  3. class sticky {
  4. #width;
  5. #height;
  6. #position;
  7. constructor() {
  8. this.#width = new auto();
  9. this.#height = new auto();
  10. this.#position = new place_top();
  11. }
  12. set width(value) {
  13. if (!(value instanceof size)) {
  14. throw "Width must be instance of size.";
  15. }
  16. this.#width = value;
  17. }
  18. set height(value) {
  19. if (!(value instanceof size)) {
  20. throw "Height must be instance of size.";
  21. }
  22. this.#height = value;
  23. }
  24. set position(value) {
  25. if (!(value instanceof position)) {
  26. throw "Position must be instance of position class.";
  27. }
  28. this.#position = value;
  29. }
  30. get element() {
  31. const container = document.createElement("div");
  32. container.style.width = this.#width.as_css;
  33. container.style.height = this.#height.as_css;
  34. container.style.position = "fixed";
  35. container.style.top = this.#position.top_css;
  36. container.style.bottom = this.#position.bottom_css;
  37. container.style.right = this.#position.right_css;
  38. container.style.left = this.#position.left_css;
  39. return container;
  40. }
  41. }
  42. export { sticky };