Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 

61 řádky
1.6 KiB

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