JavaScript Practice – Image Viewer

2019.02.27 。 Ric Huang
Step 1: Create an HTML layout
-
Download sample HTML, CSS, and images from [here]
-
Please use the class names and IDs as defined in styles.css so that the outlook can be the same as the reference.
Step 2: Write the JavsScript file
- Create an array variable that stores the URLs of the images (to show)
- Define some object variables that refer to the HTML ekements participating in the image viewing
Step 3: Create the interactions!
- 先列出所有的互動
- 針對每一個互動,先想好:
- 哪一個 element 觸發?(如:某個 <div> or <img>)
- 什麼事件觸發?(如:onclick)
- 觸發什麼樣的行為?(如:抽換圖片)
- 一些細節的設計 (如:style 的改變,loading 時的貼心設計)
<div class="image-viewer__button" onclick="previousImage()">
Step 4: Detail the JS functions
Things to consider:
- 寫程式的 Lesson 1: No duplicated codes
- Create functions to share!
- 畫面內容有什麼修改?
- element.src = '…';
- element.href = '…';
- element.innerHTML = '…';
- 呈現樣貌有什麼修改?
- element.style.property = '…';
Step 5: 一些貼心的設計
例如:
-
如果需要時間載入,背景是否有個圖以免一片空白
- Push some code before image loading
-
「計數」到達邊界時,讓按鈕的樣貌行為改變
- 如何針對同樣的觸發事件有不同的呈現樣貌?
- element.classList.add(someClass)
- element.classList.remove(someClass)
JavaScript Practice – Image Viewer 2019.02.27 。 Ric Huang
{"metaMigratedAt":"2023-06-14T20:22:25.854Z","metaMigratedFrom":"YAML","title":"JavaScript Practice -- Image Viewer (02/27)","breaks":true,"slideOptions":"{\"theme\":\"beige\",\"transition\":\"fade\",\"slidenumber\":true}","contributors":"[{\"id\":\"752a44cb-2596-4186-8de2-038ab32eec6b\",\"add\":1949,\"del\":233}]"}