ギャラリーモジュール: このモジュールは、メインギャラリーコンテナとそのコンポーネントをスタイリングします。 主な機能には次のものがあります
フルサイズの画像を保持するためのコンテナの固定高さ(500px)。 オーバーフローを防ぐために、含まれている画像(
)が含まれている場合、およびが100%に設定されています。 アクセシビリティを向上させるためのナビゲーション矢印(
)のホバーおよびフォーカススタイル。 キーボードユーザーには、視覚的な手がかりが明確に表示されます
.gallery
max-width
max-height
img
ホームページモジュール:.gallery__arrow
.gallery { position: relative; height: 500px; border: 1px solid #FFFFFF; } .gallery img { display: block; margin: 0 auto; max-width: 100%; max-height: 100%; } .gallery__arrow { position: absolute; top: 50%; display: block; width: 60px; height: 60px; border: none; border-radius: 50%; background-color: #000000; opacity: 0.7; cursor: pointer; } .gallery__arrow:hover, .gallery__arrow:focus { opacity: 1; } /* Arrow styling (before and after pseudo-elements) */ .gallery__arrow:before, .gallery__arrow:after { content: ''; position: absolute; width: 10px; height: 40%; background-color: #FFFFFF; } .gallery__arrow:before { bottom: 12px; } .gallery__arrow:after { top: 12px; } .gallery__arrow:hover:before, .gallery__arrow:focus:before, .gallery__arrow:hover:after, .gallery__arrow:focus:after { background-color: #FCB712; } /* Left and right arrow positioning and rotation */ .gallery__arrow--left { left: 0.5em; } .gallery__arrow--left:before { transform: rotate(-40deg); left: 35%; } .gallery__arrow--left:after { transform: rotate(40deg); left: 35%; } .gallery__arrow--right { right: 0.5em; } .gallery__arrow--right:before { transform: rotate(40deg); right: 35%; } .gallery__arrow--right:after { transform: rotate(-40deg); right: 35%; }
JavaScriptロジックは、iifeと厳密なモードを使用してモジュール化されています。
ユーティリティモジュール:.thumbnails__list, .thumbnails__pager { margin: 0; padding: 0; list-style-type: none; } .thumbnails__list li { display: inline-block; width: 19%; margin-top: 1%; margin-right: 1%; } .thumbnail { width: 100%; } .thumbnail:hover, .thumbnail:focus { border: 1px solid #FCB720; opacity: 0.7; } .thumbnails__pager { text-align: right; margin: 0.5em 0; } .thumbnails__pager li { display: inline; } .thumbnails__pager a { margin: 0 0.2em; color: #FFFFFF; text-decoration: none; } .thumbnails__pager a.current, .thumbnails__pager a:hover, .thumbnails__pager a:focus { color: #FCB720; text-decoration: underline; }
ギャラリーモジュール:
.form-search { margin: 0.5em 0; text-align: right; } .form-search #query { padding: 0.2em; } .form-search input { color: #000000; } .thumbnails { border-bottom: 3px solid #FFFFFF; } .copyright { margin-top: 0.5em; margin-bottom: 0.5em; text-align: right; }
で閉鎖を使用することに注意してください。
flickrモジュール:Flickr APIインタラクションを処理します。 を実際のAPIキーに置き換えることを忘れないでください
メインモジュール:
(function(document, window) { 'use strict'; function buildUrl(url, parameters) { // ... (URL building logic as before) ... } function extend(object) { // ... (Object extension logic as before) ... } window.Utility = { buildUrl: buildUrl, extend: extend }; })(document, window);
このモジュールはすべてを結び付け、ユーザーのインタラクションを処理し、他のモジュールを統合します。 矢印のポケットベールとキーボードサポートのためのイベント委任の使用に注意してください。
.gallery { position: relative; height: 500px; border: 1px solid #FFFFFF; } .gallery img { display: block; margin: 0 auto; max-width: 100%; max-height: 100%; } .gallery__arrow { position: absolute; top: 50%; display: block; width: 60px; height: 60px; border: none; border-radius: 50%; background-color: #000000; opacity: 0.7; cursor: pointer; } .gallery__arrow:hover, .gallery__arrow:focus { opacity: 1; } /* Arrow styling (before and after pseudo-elements) */ .gallery__arrow:before, .gallery__arrow:after { content: ''; position: absolute; width: 10px; height: 40%; background-color: #FFFFFF; } .gallery__arrow:before { bottom: 12px; } .gallery__arrow:after { top: 12px; } .gallery__arrow:hover:before, .gallery__arrow:focus:before, .gallery__arrow:hover:after, .gallery__arrow:focus:after { background-color: #FCB712; } /* Left and right arrow positioning and rotation */ .gallery__arrow--left { left: 0.5em; } .gallery__arrow--left:before { transform: rotate(-40deg); left: 35%; } .gallery__arrow--left:after { transform: rotate(40deg); left: 35%; } .gallery__arrow--right { right: 0.5em; } .gallery__arrow--right:before { transform: rotate(40deg); right: 35%; } .gallery__arrow--right:after { transform: rotate(-40deg); right: 35%; }
この包括的な書き込みは、元の機能を維持し、画像を元の形式に保持しながら、コードのより構造的で読みやすい説明を提供します。 プレースホルダーのコメントを元の応答から実際のコードに置き換えることを忘れないでください。 GitHubリポジトリリンクも完全性のために含める必要があります。
以上がFlickr APIで画像ギャラリーを作成しますの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。