Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 

72 rader
1.7 KiB

  1. import $ from "jquery";
  2. class IHKMagazineHeader {
  3. constructor(header) {
  4. this.header = header.addClass('initiated');
  5. this.gradient = header.find('.gradient');
  6. this.title = header.find('.title');
  7. this.window = $(window);
  8. this.minScale = 0;
  9. this.preventResize = false;
  10. this.initSizeObserver();
  11. this.initScroll();
  12. $('body')
  13. .on('overlay-open', () => {
  14. this.preventResize = true;
  15. })
  16. .on('overlay-close', () => {
  17. this.preventResize = false;
  18. })
  19. }
  20. initSizeObserver() {
  21. const observer = new ResizeObserver(() => {
  22. this.getMinScale();
  23. })
  24. observer.observe(this.header.get(0));
  25. }
  26. initScroll() {
  27. window.addEventListener("scroll", () => {
  28. window.requestAnimationFrame( () => {
  29. if (!this.preventResize) {
  30. this.checkScroll();
  31. }
  32. })
  33. },{passive: true});
  34. this.checkScroll();
  35. };
  36. checkScroll() {
  37. const st = this.window.scrollTop();
  38. let scale = 1 - Math.round(st / 4) / 100;
  39. const opacity = 1 - Math.round(st / 2) / 100;
  40. if (scale < 0) {
  41. scale = 0;
  42. }
  43. this.gradient.css({'transform': 'scale(1, ' + (scale > this.minScale ? scale : this.minScale) + ')'});
  44. this.title.css({
  45. 'transform': 'translate(-50%, -50%) scale(' + scale + ')',
  46. 'opacity': opacity > 0 ? opacity : 0
  47. })
  48. }
  49. getMinScale() {
  50. this.minScale = Math.round(1000 / this.header.outerHeight()) / 100;
  51. }
  52. }
  53. export default IHKMagazineHeader;
  54. $('body').on('ihk-init dynamic-component-loaded gfi-dynamic-init', function () {
  55. const body = $(this);
  56. $('.magazine-header:not(.initiated)').each(function(i) {
  57. new IHKMagazineHeader($(this));
  58. });
  59. })