| | |
| | | <section> |
| | | <iframe data-src="/assets/html/css-grid-example-4.html"></iframe> |
| | | </section> |
| | | <section> |
| | | <h3>Media Queries</h3> |
| | | <ul> |
| | | <li>"Medienabfragen"</li> |
| | | <li>Styles auf Basis von Eigenschaften des Ausgabemediums</li> |
| | | <li>Große Bildschirme, kleine Bildschirme, Printmedien...</li> |
| | | <li>Hinweis: Sollten immer als letztes (unten) in einem Stylesheet sein</li> |
| | | </ul> |
| | | </section> |
| | | <section> |
| | | <h3>Syntax</h3> |
| | | <pre> |
| | | <code class="css" data-trim data-line-numbers> |
| | | @media screen and (min-width: 640px) and (max-width: 1024px) { |
| | | .navigation { |
| | | display: none; |
| | | } |
| | | } |
| | | </code> |
| | | </pre> |
| | | <p>Bedeutung: Wenn die Seite auf einem Display angezeigt wird, welches zwischen 640px und 1024px in der Breite anzeigen kann, dann blende die Navigation aus</p> |
| | | </section> |
| | | <section> |
| | | <h3>Werte für die Ausgabemedien (optional, Standard ist "all")</h3> |
| | | <ul> |
| | | <li>all</li> |
| | | <li>screen</li> |
| | | <li>print</li> |
| | | </ul> |
| | | </section> |
| | | <section> |
| | | <h3>Werte für die Eigenschaften mit Typ und Erklärung (kleiner Auszug)</h3> |
| | | <ul> |
| | | <li>width (Number, Breite)</li> |
| | | <li>height (Number, Höhe)</li> |
| | | <li>orientation (portrait | landscape, Quer- oder Hochformat)</li> |
| | | <li>hover (none | hover, Hat Zeiger zum Hovern)</li> |
| | | <li>forced-colors (none | active, erzwungene Farbpalette z.B. bei Sehbehinderung)</li> |
| | | </ul> |
| | | </section> |
| | | <section> |
| | | <h3>Aufgabe</h3> |
| | | <p>Entwerfe eine kleine Seite mit @media und zeige ein beliebiges Element ab einer bestimmten Höhe oder Breite an (die Größe des Displays kann dynamisch mit den Entwicklertools im Gerätesimulator geändert werden)</p> |
| | | </section> |
| | | <section> |
| | | <h3>Aufgabe</h3> |
| | | <p>Passe die Vorlage "media-queries-responsive-layout.html" mit @media-Queries so an, dass das Menü links ab einer maximalen Breite von 480 Pixel und kleiner nach links oben in die Ecke minimiert wird und nur per Hover wieder 50% Breite und 100% Höhe bekommt</p> |
| | | </section> |
| | | <section> |
| | | <img data-src="/assets/images/media-queries-excercise.png"> |
| | | </section> |
| | | <section> |
| | | <h3>Lösung</h3> |
| | | <pre> |
| | | <code class="css" data-trim data-line-numbers> |
| | | @media screen and (max-width: 480px) { |
| | | .menu { |
| | | grid-area: unset; |
| | | |
| | | position: absolute; |
| | | } |
| | | |
| | | .menu:hover { |
| | | height: 100%; |
| | | width: 50%; |
| | | } |
| | | |
| | | .grid { |
| | | grid-template-columns: 0fr 5fr; |
| | | } |
| | | } |
| | | </code> |
| | | </pre> |
| | | </section> |
| | | <section> |
| | | <h3>Transform</h3> |
| | | <ul> |
| | | <li>rein optisch, d.h. "physische" Größe bleibt erhalten</li> |
| | | <li>eine Art "Shader" auf Grafikebene</li> |
| | | <li>Effekte wie Drehung, Vergrößerung, Verschiebung usw.</li> |
| | | </ul> |
| | | </section> |
| | | <section> |
| | | <h3>Syntax</h3> |
| | | <pre> |
| | | <code class="css" data-trim data-line-numbers> |
| | | .foo { |
| | | transform: translateX(20px) translateY(20px); |
| | | transform-origin: left; |
| | | } |
| | | </code> |
| | | </pre> |
| | | </section> |
| | | <section> |
| | | <h3>Mögliche Effekte</h3> |
| | | <ul> |
| | | <li>translate</li> |
| | | <li>rotate</li> |
| | | <li>scale</li> |
| | | <li>scew</li> |
| | | </ul> |
| | | <p>Die meisten besitzen zusätzlich spezifischere X-, Y- oder 3D-Versionen</p> |
| | | </section> |
| | | <section> |
| | | <h3>Aufgabe</h3> |
| | | <p>Probiere die genannten Transform-Effekte in einer beliebigen Seite aus</p> |
| | | </section> |
| | | <section> |
| | | <h3>Transition</h3> |
| | | <ul> |
| | | <li>Elemente können "weich" verändert werden</li> |
| | | <li>Mögliche Attribute, deren Änderungen animiert werden können sind z.B. <code>width</code>, <code>height</code>, <code>transform</code>, <code>color</code> und viele weitere</li> |
| | | <li>Das Attribut <code>display</code> lässt sich jedoch nicht animieren</li> |
| | | </ul> |
| | | </section> |
| | | <section> |
| | | <h3>Syntax</h3> |
| | | <pre> |
| | | <code class="css" data-trim data-line-numbers> |
| | | .foo { |
| | | width: 100%; |
| | | background-color: red; |
| | | /* transition: [Attribut] [Dauer] [Zeitfunktion] */ |
| | | transition: width 1s ease-out; |
| | | } |
| | | |
| | | .foo:hover { |
| | | width: 50%; |
| | | } |
| | | </code> |
| | | </pre> |
| | | </section> |
| | | <section> |
| | | <h3>Beispiel</h3> |
| | | <iframe data-src="/assets/html/css-transition.html"></iframe> |
| | | </section> |
| | | <section> |
| | | <h3>Animation</h3> |
| | | <ul> |
| | | <li>Es können zusätzlich eigene Animationen entworfen werden</li> |
| | | <li>Definition per <code>Keyframes</code></li> |
| | | </ul> |
| | | </section> |
| | | <section> |
| | | <h3>Syntax</h3> |
| | | <pre> |
| | | <code class="css" data-trim data-line-numbers> |
| | | .foo { |
| | | animation-duration: 3s; |
| | | animation-name: slidein; |
| | | } |
| | | |
| | | @keyframes slidein { |
| | | from { |
| | | margin-left: 100%; |
| | | width: 300%; |
| | | } |
| | | |
| | | to { |
| | | margin-left: 0%; |
| | | width: 100%; |
| | | } |
| | | } |
| | | </code> |
| | | </pre> |
| | | </section> |
| | | <section> |
| | | <h3>Alternative Syntax</h3> |
| | | <pre> |
| | | <code class="css" data-trim data-line-numbers> |
| | | .foo { |
| | | /* ... */ |
| | | } |
| | | |
| | | @keyframes slidein { |
| | | 1% { |
| | | margin-left: 100%; |
| | | } |
| | | |
| | | 100% { |
| | | margin-left: 0%; |
| | | } |
| | | } |
| | | </code> |
| | | </pre> |
| | | </section> |
| | | <section> |
| | | <h3>Beispiel</h3> |
| | | <iframe data-src="/assets/html/css-animation.html"></iframe> |
| | | </section> |
| | | <section> |
| | | <h3>3D Transform</h3> |
| | | <ul> |
| | | <li>Neben den gewohnten X- und Y-Achsen (Breite und Höhe) gibt es auch noch die Z-Achse</li> |
| | | <li>Bewegung entlang der Sichtachse, d.h. zum bzw. vom Betrachter weg</li> |
| | | <li>Perspektivische Effekte möglich</li> |
| | | </ul> |
| | | </section> |
| | | <section> |
| | | <h3>Beispiel</h3> |
| | | <iframe data-src="/assets/html/css-transform-3d.html"></iframe> |
| | | </section> |
| | | <section> |
| | | <h3>Bedingungen / Optionen</h3> |
| | | <pre> |
| | | <code class="css" data-trim data-line-numbers> |
| | | .container { |
| | | perspective: 1000px; /* "Entfernung" des Betrachters */ |
| | | |
| | | transform-style: preserve-3d; /* oder "flat" */ |
| | | } |
| | | |
| | | .element { |
| | | backface-visibility: hidden; /* oder "visible" */ |
| | | } |
| | | </code> |
| | | </pre> |
| | | </section> |
| | | <section> |
| | | <h3>Beispiel</h3> |
| | | <iframe data-src="/assets/html/css-transform-3d-cube.html"></iframe> |
| | | </section> |
| | | <section> |
| | | <h3>Aufgabe</h3> |
| | | <p>Implementiere einen drehenden Würfel (Vorlage "templates/008-css/css-3d-cube.html")</p> |
| | | </section> |
| | | </section> |
| | | <section> |
| | | <section> |
| | | <h2>Web Components</h2> |
| | | </section> |
| | | <section> |
| | | <p>Was sind Web Components?</p> |
| | | <img data-src="/assets/images/web-components.svg"> |
| | | </section> |
| | | <section> |
| | | <p>Vorteile</p> |
| | | <ul> |
| | | <li>Entwicklung eigener HTML-Elemente, welche sich nahtlos neben nativen Elementen nutzen lassen</li> |
| | | <li>Hohe Wiederverwendbarkeit in mehreren Projekten</li> |
| | | <li>Keine Libraries oder Frameworks notwendig, um eigene Elemente zu entwickeln</li> |
| | | <li>Kapselung des Scopes sowohl von JS (Variablen...) als auch CSS (id, class...)</li> |
| | | </ul> |
| | | </section> |
| | | <section> |
| | | <h3>Ansätze in der Vergangenheit und Alternativen heute</h3> |
| | | </section> |
| | | <section> |
| | | <h4>jQuery</h4> |
| | | <a href="https://api.jqueryui.com/accordion/#entry-examples" target="_blank">https://api.jqueryui.com/accordion/#entry-examples</a> |
| | | </section> |
| | | <section> |
| | | <pre> |
| | | <code class="html" data-trim data-line-numbers> |
| | | <script type="text/template"> |
| | | <div id="accordion" class="ui-accordion ui-widget ui-helper-reset" role="tablist"> |
| | | <h3 class="ui-accordion-header ui-corner-top ui-state-default ui-accordion-icons ui-accordion-header-active ui-state-active" role="tab" id="ui-id-1" aria-controls="ui-id-2" aria-selected="true" aria-expanded="true" tabindex="0"> |
| | | <span class="ui-accordion-header-icon ui-icon ui-icon-triangle-1-s"></span>Section 1</h3> |
| | | <div class="ui-accordion-content ui-corner-bottom ui-helper-reset ui-widget-content ui-accordion-content-active" id="ui-id-2" aria-labelledby="ui-id-1" role="tabpanel" aria-hidden="false" style="display: block; height: 166.8px;"> |
| | | <p>Mauris mauris ante, blandit et, ultrices a, suscipit eget. |
| | | Integer ut neque. Vivamus nisi metus, molestie vel, gravida in, |
| | | condimentum sit amet, nunc. Nam a nibh. Donec suscipit eros. |
| | | Nam mi. Proin viverra leo ut odio.</p> |
| | | </div> |
| | | <h3 class="ui-accordion-header ui-corner-top ui-state-default ui-accordion-icons ui-accordion-header-collapsed ui-corner-all" role="tab" id="ui-id-3" aria-controls="ui-id-4" aria-selected="false" aria-expanded="false" tabindex="-1"><span class="ui-accordion-header-icon ui-icon ui-icon-triangle-1-e"></span>Section 2</h3> |
| | | <div class="ui-accordion-content ui-corner-bottom ui-helper-reset ui-widget-content" id="ui-id-4" aria-labelledby="ui-id-3" role="tabpanel" aria-hidden="true" style="display: none; height: 166.8px;"> |
| | | <p>Sed non urna. Phasellus eu ligula. Vestibulum sit amet purus. |
| | | Vivamus hendrerit, dolor aliquet laoreet, mauris turpis velit, |
| | | faucibus interdum tellus libero ac justo.</p> |
| | | </div> |
| | | <h3 class="ui-accordion-header ui-corner-top ui-state-default ui-accordion-icons ui-accordion-header-collapsed ui-corner-all" role="tab" id="ui-id-5" aria-controls="ui-id-6" aria-selected="false" aria-expanded="false" tabindex="-1"><span class="ui-accordion-header-icon ui-icon ui-icon-triangle-1-e"></span>Section 3</h3> |
| | | <div class="ui-accordion-content ui-corner-bottom ui-helper-reset ui-widget-content" id="ui-id-6" aria-labelledby="ui-id-5" role="tabpanel" aria-hidden="true" style="display: none; height: 166.8px;"> |
| | | <p>Nam enim risus, molestie et, porta ac, aliquam ac, risus. |
| | | Quisque lobortis.Phasellus pellentesque purus in massa.</p> |
| | | <ul> |
| | | <li>List item one</li> |
| | | <li>List item two</li> |
| | | <li>List item three</li> |
| | | </ul> |
| | | </div> |
| | | </div> |
| | | </script> |
| | | </code> |
| | | </pre> |
| | | </section> |
| | | <section> |
| | | <h4>angular</h4> |
| | | <img data-src="/assets/images/web-components-angular.png"> |
| | | </section> |
| | | <section> |
| | | <pre> |
| | | <code class="html" data-trim data-line-numbers> |
| | | <script type="text/template"> |
| | | <app-root _nghost-ng-c3715250071="" ng-version="17.0.0"><app-top-bar _ngcontent-ng-c3715250071="" _nghost-ng-c3918259376=""><a _ngcontent-ng-c3918259376="" routerlink="/" ng-reflect-router-link="/" href="/"><h1 _ngcontent-ng-c3918259376="">My Store</h1></a><a _ngcontent-ng-c3918259376="" routerlink="/cart" class="button fancy-button" ng-reflect-router-link="/cart" href="/cart"><em _ngcontent-ng-c3918259376="" class="material-icons">shopping_cart</em>Checkout |
| | | </a></app-top-bar><div _ngcontent-ng-c3715250071="" class="container"><router-outlet _ngcontent-ng-c3715250071=""></router-outlet><app-product-list _nghost-ng-c2837874410=""><h2 _ngcontent-ng-c2837874410="">Products</h2><div _ngcontent-ng-c2837874410=""><h3 _ngcontent-ng-c2837874410=""><a _ngcontent-ng-c2837874410="" title="Phone XL details" ng-reflect-router-link="/products,1" href="/products/1"> Phone XL </a></h3><p _ngcontent-ng-c2837874410=""> Description: A large phone with one of the best screens </p><!--bindings={ |
| | | "ng-reflect-ng-if": "A large phone with one of the " |
| | | }--><button _ngcontent-ng-c2837874410="" type="button"> Share </button><app-product-alerts _ngcontent-ng-c2837874410="" _nghost-ng-c869072018="" ng-reflect-product="[object Object]"><p _ngcontent-ng-c869072018=""><button _ngcontent-ng-c869072018="" type="button">Notify Me</button></p><!--bindings={ |
| | | "ng-reflect-ng-if": "true" |
| | | }--></app-product-alerts></div><div _ngcontent-ng-c2837874410=""><h3 _ngcontent-ng-c2837874410=""><a _ngcontent-ng-c2837874410="" title="Phone Mini details" ng-reflect-router-link="/products,2" href="/products/2"> Phone Mini </a></h3><p _ngcontent-ng-c2837874410=""> Description: A great phone with one of the best cameras </p><!--bindings={ |
| | | "ng-reflect-ng-if": "A great phone with one of the " |
| | | }--><button _ngcontent-ng-c2837874410="" type="button"> Share </button><app-product-alerts _ngcontent-ng-c2837874410="" _nghost-ng-c869072018="" ng-reflect-product="[object Object]"><!--bindings={ |
| | | "ng-reflect-ng-if": "false" |
| | | }--></app-product-alerts></div><div _ngcontent-ng-c2837874410=""><h3 _ngcontent-ng-c2837874410=""><a _ngcontent-ng-c2837874410="" title="Phone Standard details" ng-reflect-router-link="/products,3" href="/products/3"> Phone Standard </a></h3><!--bindings={ |
| | | "ng-reflect-ng-if": "" |
| | | }--><button _ngcontent-ng-c2837874410="" type="button"> Share </button><app-product-alerts _ngcontent-ng-c2837874410="" _nghost-ng-c869072018="" ng-reflect-product="[object Object]"><!--bindings={ |
| | | "ng-reflect-ng-if": "false" |
| | | }--></app-product-alerts></div><!--bindings={ |
| | | "ng-reflect-ng-for-of": "[object Object],[object Object" |
| | | }--></app-product-list><!--container--></div> |
| | | </app-root> |
| | | </script> |
| | | </code> |
| | | </pre> |
| | | </section> |
| | | <section> |
| | | <h3>Aufbau einer Web Component</h3> |
| | | <pre> |
| | | <code class="html" data-trim data-line-numbers> |
| | | <script type="text/template"> |
| | | <!-- |
| | | Hinweis: Der Name bzw. der Selektor muss immer einen Bindestrich enthalten, |
| | | damit keine Namens-Kollisionen mit nativen HTML-Tags entstehen können |
| | | --> |
| | | <hello-world></hello-world> |
| | | </script> |
| | | </code> |
| | | </pre> |
| | | </section> |
| | | <section> |
| | | <pre> |
| | | <code class="js" data-trim data-line-numbers="1-16|19"> |
| | | <script type="text/template"> |
| | | class HelloWorldComponent extends HTMLElement { |
| | | constructor() { |
| | | super(); |
| | | |
| | | const shadowRoot = this.attachShadow({mode: "open"}); |
| | | |
| | | shadowRoot.innerHTML = ` |
| | | <style> |
| | | div { |
| | | background-color: coral; |
| | | color: white; |
| | | } |
| | | </style> |
| | | <div>Hello World!</div> |
| | | `; |
| | | } |
| | | } |
| | | |
| | | window.customElements.define("hello-world", HelloWorldComponent); |
| | | </script> |
| | | </code> |
| | | </pre> |
| | | </section> |
| | | <section> |
| | | <iframe data-src="/assets/html/hello-world.html"></iframe> |
| | | </section> |
| | | <section> |
| | | <h4>Light DOM vs Shadow DOM</h4> |
| | | <img data-src="/assets/images/web-components-shadow-root.png" width="500px"> |
| | | </section> |
| | | <section> |
| | | <h4>Suche von Elementen im Light- und Shadow DOM</h4> |
| | | <pre> |
| | | <code class="js" data-trim data-line-numbers> |
| | | <script type="text/template"> |
| | | // Light DOM |
| | | const span = document.querySelector("span"); // Hi! |
| | | const divs = document.querySelectorAll("div"); |
| | | |
| | | console.log(divs.length); // => 1 |
| | | |
| | | // Shadow DOM |
| | | const helloWorld = document.querySelector("hello-world"); |
| | | |
| | | helloWorld.shadowRoot.querySelector("div"); // Hello World! |
| | | </script> |
| | | </code> |
| | | </pre> |
| | | </section> |
| | | <section> |
| | | <h3>Auf Attribute reagieren</h3> |
| | | <pre> |
| | | <code class="js" data-trim data-line-numbers="2|8-10"> |
| | | <script type="text/template"> |
| | | class HelloWorldComponent extends HTMLElement { |
| | | static observedAttributes = ["my-attribute"]; |
| | | |
| | | constructor() { |
| | | // ... |
| | | } |
| | | |
| | | attributeChangedCallback(name, oldValue, newValue) { |
| | | console.log(`${name}: changed from ${oldValue} to ${newValue}`); |
| | | } |
| | | } |
| | | </script> |
| | | </code> |
| | | </pre> |
| | | </section> |
| | | <section> |
| | | <h3>Aufgabe</h3> |
| | | <p>Lasse die eigene Komponente "hello-sayer" auf eine Änderung des "name"-Attributs reagieren, indem der dort eingetragene Name in der Komponente angezeigt wird (Beispiel: name="Joe" => Hello Joe!)</p> |
| | | <p>(/examples/templates/web-components/hello-sayer.html)</p> |
| | | </section> |
| | | <section> |
| | | <h3>Musterlösung</h3> |
| | | <pre> |
| | | <code class="js" data-trim data-line-numbers> |
| | | <script type="text/template"> |
| | | class HelloSayerComponent extends HTMLElement { |
| | | static observedAttributes = ["name"]; |
| | | |
| | | constructor() { |
| | | super(); |
| | | |
| | | this.root = this.attachShadow({mode: "open"}); |
| | | |
| | | this.root.innerHTML = ` |
| | | <style> |
| | | div { |
| | | background-color: coral; |
| | | color: white; |
| | | } |
| | | </style> |
| | | <div>Hello!</div> |
| | | `; |
| | | } |
| | | |
| | | attributeChangedCallback(name, oldValue, newValue) { |
| | | this.root.querySelector("div").innerHTML = `Hello ${newValue}!`; |
| | | } |
| | | } |
| | | |
| | | window.customElements.define("hello-sayer", HelloSayerComponent); |
| | | |
| | | const names = ["Joe", "Allie"]; |
| | | let counter = 0; |
| | | |
| | | setInterval(() => document.querySelector("hello-sayer").setAttribute("name", names[counter++ % 2]), 2000); |
| | | </script> |
| | | </code> |
| | | </pre> |
| | | </section> |
| | | <section> |
| | | <iframe data-src="/assets/html/hello-sayer.html"></iframe> |
| | | </section> |
| | | </section> |
| | | </div> |
| | | </div> |