From fca0f491195f1ca804bf7a19687d7e1edba2ceb5 Mon Sep 17 00:00:00 2001 From: "konstantina.galouni" Date: Fri, 28 Jan 2022 11:01:22 +0200 Subject: [PATCH] [new-theme | Library]: section-scroll.component: Scroll component used by connect home page updated - opacity changes according to intersectionRatio of IntersectionObserver | css for medium screens added. --- .../section-scroll.component.css | 79 ++++++++----- .../section-scroll.component.ts | 107 ++++++++++++++---- 2 files changed, 134 insertions(+), 52 deletions(-) diff --git a/utils/section-scroll/section-scroll.component.css b/utils/section-scroll/section-scroll.component.css index 2dd17209..083e5faa 100644 --- a/utils/section-scroll/section-scroll.component.css +++ b/utils/section-scroll/section-scroll.component.css @@ -1,44 +1,65 @@ -.section { - position: relative; - height: auto; +/*.section {*/ + /*position: relative;*/ + /*height: auto;*/ /*display: flex;*/ -} +/*}*/ -.section [top] { - /*height: 80vh;*/ - /*border: 1px solid rebeccapurple;*/ -} +/*.section [top] {*/ +/* !*height: 80vh;*!*/ +/* !*border: 1px solid rebeccapurple;*!*/ +/*}*/ -.section [top] { - position: sticky; - top: 0; - z-index: 2; - height: auto; - /*max-height: 80vh;*/ - /*border: 1px solid deeppink;*/ -} - -/*.content {*/ -/* position: relative;*/ +/*.section [top] {*/ +/* top: 0;*/ /* height: auto;*/ -/* z-index: 1;*/ -/* border: 1px solid cyan;*/ +/* !*border: 1px solid deeppink;*!*/ /*}*/ [left] { + position: -webkit-sticky; /* Safari */ position: sticky; top: 0; height: 100vh; /*border: 1px solid red;*/ } -[left] img { - /*position: absolute;*/ - /*top: 50%;*/ - /*left: 50%;*/ - /*transform: translate(-50%, -50%);*/ - position: sticky; - top: 50%; - left: 10%; +[left] .imgContainer { + position: absolute; + top: 20%; + left: 0; + width: 100%; + height: 70%; /*border: 1px solid greenyellow;*/ } + +@media (max-width: 960px) { + [left] .imgContainer { + top: 5%; + height: 40%; + } + + [left] > * { + align-items: flex-start; + } + + [scroll] > * { + align-items: flex-end; + } +} + +[left] img { + width: auto; + height: auto; + max-width: 100%; + max-height: 100%; +} + +[scroll] { + margin-top: 15vh; + margin-bottom: 25vh; +} + +[scroll] > * { + height: 60vh; + /* border: 1px solid darkorange;*/ +} \ No newline at end of file diff --git a/utils/section-scroll/section-scroll.component.ts b/utils/section-scroll/section-scroll.component.ts index fb8ae08d..ddfcbc26 100644 --- a/utils/section-scroll/section-scroll.component.ts +++ b/utils/section-scroll/section-scroll.component.ts @@ -2,30 +2,26 @@ import {Component, HostListener, Input, OnInit, ViewEncapsulation} from "@angula /** - * - *
...
- *
...
# use uk-flex-first to change order + * + *
...
+ *
...
+ *
...
*
* * */ @Component({ selector: 'section-scroll', template: ` - - - - - - - - - - -
- - - -
+
+ +
+
+ + +
+
+
`, styleUrls: ['section-scroll.component.css'], encapsulation: ViewEncapsulation.None @@ -38,16 +34,22 @@ export class SectionScrollComponent implements OnInit { public childrenCustomClass = null; private absolute: HTMLCollectionOf; private scroll: HTMLElement; - - constructor() { - } - + + private observer: IntersectionObserver = null; + + constructor() {} + @HostListener('window:resize', ['$event']) onResize(event) { //this.setHeight(); } - + ngOnDestroy() { + if(this.observer) { + this.observer.disconnect(); + } + } + ngOnInit() { //this.setHeight(); } @@ -66,4 +68,63 @@ export class SectionScrollComponent implements OnInit { let htmlElement = this.absolute&&this.absolute.length>0?this.absolute[0]:null; return htmlElement?htmlElement['offsetHeight']:0; } + + ngAfterViewInit() { + if(typeof document !== "undefined") { + this.createObserver(); + } + } + + createObserver() { + let observer; + + let options = { + root: null, + rootMargin: "-20%", + threshold: this.buildThresholdList() + }; + + let imgElement1: HTMLElement = document.getElementById("imgId1"); + let imgElement2: HTMLElement = document.getElementById("imgId2"); + let imgElement3: HTMLElement = document.getElementById("imgId3"); + let imgElement4: HTMLElement = document.getElementById("imgId4"); + let imgElement5: HTMLElement = document.getElementById("imgId5"); + + observer = new IntersectionObserver(entries => { + entries.forEach((entry) => { + entry.target['style'].opacity = entry.intersectionRatio; + + if (entry.target.id == "1st") { + imgElement1.parentElement.style.opacity = String(entry.intersectionRatio); + } else if (entry.target.id == "2nd") { + imgElement2.parentElement.style.opacity = String(entry.intersectionRatio); + } else if (entry.target.id == "3rd") { + imgElement3.parentElement.style.opacity = String(entry.intersectionRatio); + } else if (entry.target.id == "4th") { + imgElement4.parentElement.style.opacity = String(entry.intersectionRatio); + } else if (entry.target.id == "5th") { + imgElement5.parentElement.style.opacity = String(entry.intersectionRatio); + } + }); + }, options); + + let targets: NodeListOf = document.getElementsByName('txt'); + targets.forEach(target => + { + observer.observe(target) + }); + } + + buildThresholdList() { + let thresholds = []; + let numSteps = 20; + + for (let i=1.0; i<=numSteps; i++) { + let ratio = i/numSteps; + thresholds.push(ratio); + } + + thresholds.push(0); + return thresholds; + } }