<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ashley Yang on Medium]]></title>
        <description><![CDATA[Stories by Ashley Yang on Medium]]></description>
        <link>https://medium.com/@ash.hana?source=rss-b3e844bf285a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*fQR8RRIEO19Ng41pBeMEMw@2x.jpeg</url>
            <title>Stories by Ashley Yang on Medium</title>
            <link>https://medium.com/@ash.hana?source=rss-b3e844bf285a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 07:58:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ash.hana/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[超越傳統電商限制：Headless CMS 與 Shopify 的創新整合策略]]></title>
            <link>https://medium.com/tomofun-tech-blog/headless-cms-shopify-integration-strategy-b7c682dc77c5?source=rss-b3e844bf285a------2</link>
            <guid isPermaLink="false">https://medium.com/p/b7c682dc77c5</guid>
            <category><![CDATA[ecommerce-solution]]></category>
            <category><![CDATA[shopify]]></category>
            <category><![CDATA[tomofun]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[headless-cms]]></category>
            <dc:creator><![CDATA[Ashley Yang]]></dc:creator>
            <pubDate>Wed, 15 May 2024 03:39:22 GMT</pubDate>
            <atom:updated>2024-05-15T03:39:22.983Z</atom:updated>
            <content:encoded><![CDATA[<h3>超越傳統電商限制：Headless CMS 與Shopify 的創新整合策略</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QJL8soVePApLijiJQCTfHw.jpeg" /></figure><blockquote>隨著電商市場的高速發展，依賴傳統平台如 Shopify 已無法全面滿足企業迅速跨境擴展的多樣化需求。面對這一挑戰，Tomofun 引進 Headless CMS 技術並與 Shopify 進行整合。此創新策略不僅提升了我們的運營效率，還大幅增強了對全球市場需求的靈活應對能力，為客戶帶來了即時且個性化的購物體驗。</blockquote><p>在 Tomofun 發展初期，Shopify 確實帶給我們建立電商網站的便利性。但隨著 Furbo 產品在全球市場的迅猛擴張，MKT 需要一個可以和客戶快速溝通及銷售的平台，因此，Shopify 高度依賴 Liquid 模板語言的客製化要求，為非技術人員帶來了學習上的挑戰，這不僅增加了操作成本，也影響了市場的快速反應能力。因此，尋找一個更靈活、可擴展的解決方案成了我們的迫切需求。</p><h3>什麼是 Headless CMS</h3><figure><img alt="Headless CMS vs. Traditional CMS (https://prismic.io/blog/headless-cms-vs-traditional-cms)" src="https://cdn-images-1.medium.com/max/1024/0*5nqINKeie7-1WXYf" /><figcaption>Headless CMS vs. Traditional CMS (https://prismic.io/blog/headless-cms-vs-traditional-cms)</figcaption></figure><p>不同於傳統的 CMS，Headless CMS 通過前後端分離的架構，使得內容通過API 在任何裝置上展現，從而為開發者提供更大的自由度來適應各種前端技術和平台。這種架構不僅為技術人員帶來了便利，也極大地提升了非技術團隊的工作效率：</p><h4>對非技術人員的優勢</h4><ul><li>靈活的系統整合：允許內容跨前端框架發布，提升了跨系統整合的便捷性。</li><li>簡化的操作介面：提供一個友好的用戶介面，使技術和非技術團隊成員可以方便地共同協作，無需深入了解底層技術細節。</li><li>內容的多平台重用：一次創建，多處應用，極大地節省了內容管理的時間與資源。</li></ul><h4>對前端工程師的優勢</h4><ul><li>減輕安全和管理負擔：Headless CMS 服務商負責維護和更新平台，前端工程師可以專注於優化用戶體驗。</li><li>適應未來發展需求：前後端分離，使前端團隊能自由地更新網站外觀與功能，並在需要時無縫切換到新的技術棧或平台。</li><li>提升網站性能：易於利用現代技術如靜態網站生成器，提高網站載入速度和性能。</li></ul><h3>Headless CMS 與 Shopify 整合的優勢</h3><p>除了前端網頁管理及客製化系統，Shopify 依舊有其他強大的電商功能，例如：產品管理、物流及支付方式在地化、結帳流程國際化等等，這對跨國後勤作業管理而言是極大的幫助。</p><p>通過 Headless CMS 和 Shopify 的整合，保留 Shopify 強大的電商功能，又不受其平台限制，實現更加多元和靈活的內容交付策略。這種結合方式還幫助我們解決了多語言和跨境運營的挑戰，確保了全球擴張的順利進行。</p><h3>實際案例分析</h3><p>在這次的技術升級案例中，我們成功地將 Headless CMS 與 Shopify 的強大功能結合起來，以優化整個電子商務平台。</p><h4>Headless CMS 與 Shopify 的整合策略</h4><p>我們將 Furbo 電商網站的用戶界面分為「購物前」和「結帳」兩大部分。</p><p>在購物前階段，所有的頁面如首頁、產品介紹頁和部落格等，均通過 Headless CMS 管理，並利用 NextJS ISR 動態生成，部署於 AWS Amplify，以提供更快的頁面載入速度和更佳的 SEO 表現。</p><p>當用戶進入結帳流程後，則通過 URL Redirection，轉至 Shopify 提供的結帳流程，此部分完美地整合了在地化的支付方式和物流服務，保證了交易的安全性和便利性。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pwrGgf-nCobG4NS15WGcXQ.png" /><figcaption>As is: Multiple Shopify Stores (1 Country to 1 Shopify Store)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FSOQmAxWKPkevK_vZYgYiw.png" /><figcaption>To be: Decoupled Flow for Landings and Checkout flow. (1 CMS to 15 eComm Landings + 4 Languages Blog)</figcaption></figure><h4>整合前後的效益</h4><p>此技術實施不僅顯著提升了用戶體驗，還大幅改進了運營效率。過去，在 Shopify 平台上實現客製化需求，尤其是在高銷售季節，前端團隊需投入大量人力進行網頁調整。現在，這些調整可以通過非技術人員在 CMS 後台迅速完成，大大降低了對前端開發資源的依賴。</p><p>舉例來說，一個銷售活動可能「至少」是以下兩個區塊的改動：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zqsR0pF1XOZHzsesDo0biQ.png" /><figcaption>Campaign Element</figcaption></figure><ul><li>Campaign Banner (紅色區域)：內容、左右圖示、背景顏色、內容顏色</li><li>Key Visual (橘色區域)：背景圖片、主要文字、是否顯示按鈕、按鈕樣式、按鈕行為</li></ul><p>而這兩個區塊都支援多內容輪播，另外可能還會有日常的內容調整，如 Key Visual (橘色區域)裡「貓、狗入口」的文字、導轉連結、樣式。</p><p>在年度黑色星期五至聖誕節銷售季期間，我們實現了</p><blockquote>🎉平均每一個銷售活動，減少了62%的人力 🎉</blockquote><p>這不僅提升了反應市場的速度，也使得團隊能夠更加集中精力於創新和改進其他關鍵性能指標，例如：系統和<a href="https://medium.com/tomofun-tech-blog/%E7%B6%B2%E7%AB%99%E6%95%88%E8%83%BD%E6%9C%89%E6%84%9F%E5%84%AA%E5%8C%96-aeeb600943c6">效能優化</a>等。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*quUekysO56kDtTlLWGOy_w.png" /><figcaption>From Maintenance to Engineering Excellence</figcaption></figure><h3>技術實施步驟</h3><p>實施 Headless CMS 與 Shopify 整合的過程分為三個階段：</p><ul><li><strong>階段一：策劃 → 最小可行版本的成功部署和評估<br></strong>選擇流量大但可控的市場進行最小可行產品部署，評估其穩定性並根據反饋進行初步優化。</li><li><strong>階段二： 15個 </strong><a href="https://furbo.com/"><strong>Furbo 電商網站</strong></a><strong>的全球部署<br></strong>擴展 Headless CMS 與 Shopify 的整合到其他 14 個國家，不僅提高了我們網站的性能和可用性，更確保了無縫的全球運營。</li><li><strong>階段三：4個語言的 </strong><a href="https://furbo.com/blog"><strong>Furbo 部落格</strong></a><strong>的全球部署<br></strong>將 Headless CMS 整合到 4 種不同語言的 Furbo 部落格中，並確保所有語言版本的內容的有效管理和更新。</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6wIMHZSEJczAhMYDTduPog.png" /><figcaption>Headless CMS Integration Phases Breakdown</figcaption></figure><h3>下一步計劃</h3><p>為了進一步提升靈活性和內容的重用性，我們計劃持續優化 CMS 設計，簡化內容更新流程，並提升非技術人員操作的便利性。此外，我們也在探索如何將 Shopify 最新的 <a href="https://help.shopify.com/zh-CN/en/manual/markets">Shopify Market</a> 及 <a href="https://www.shopify.com/plus/solutions/headless-commerce">Headless eCommerce</a> 更好地融合至我們的結帳流程中，以進一步提高跨國營運的效率。</p><h3>結語</h3><p>隨著 Headless CMS 和 Shopify 的成功整合，Tomofun 不僅突破了傳統電商平台的界限，更在全球市場中確立了創新的標杆。這場變革顯著提升了我們的運營效率，並大幅改善了用戶體驗，使我們能夠迅速且有效地回應全球各地市場的變化。未來，我們將繼續探索和實施更多創新解決方案，以確保 Tomofun 在寵物 AIoT 的全球電商領域保持領先。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b7c682dc77c5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/tomofun-tech-blog/headless-cms-shopify-integration-strategy-b7c682dc77c5">超越傳統電商限制：Headless CMS 與 Shopify 的創新整合策略</a> was originally published in <a href="https://medium.com/tomofun-tech-blog">Tomofun Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Firefox 67之後開始支援word-break: break-word]]></title>
            <link>https://medium.com/@ash.hana/firefox-67%E4%B9%8B%E5%BE%8C%E9%96%8B%E5%A7%8B%E6%94%AF%E6%8F%B4word-break-break-word-3079105bb106?source=rss-b3e844bf285a------2</link>
            <guid isPermaLink="false">https://medium.com/p/3079105bb106</guid>
            <category><![CDATA[firefox]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[ui]]></category>
            <dc:creator><![CDATA[Ashley Yang]]></dc:creator>
            <pubDate>Wed, 13 Nov 2019 09:57:14 GMT</pubDate>
            <atom:updated>2019-11-13T09:57:14.572Z</atom:updated>
            <content:encoded><![CDATA[<p>做前端開發時常常會遇到處理文字超出容器寬度時斷行以及斷句的需求，考量到使用者閱讀的方便性以及避免句子溢位導致跑版，大部分會以word-break: break-word;實作，將超出範圍的句子以”字”分隔做斷行，如下：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/338/1*S8-cCCITTNTtmAeRW8FFFQ.png" /></figure><p>只要是有多年前端開發經驗的人應該都知道，Firefox對word-break的支援度<strong>相當低</strong>，針對Firefox更常有的workaround是：<strong><em>如果不能斷在字跟字中間，那就斷在字母跟字母之間吧</em></strong><em>！</em></p><p>以下做法是更常見的實作：</p><pre>word-break: break-all; /* For Firefox */<br>word-break: break-word; /* For other browser which is supported */</pre><p>幾週前在處理跨瀏覽器的斷行時意外發現在某feature開發時CSS裡忘了加上word-break: break-all，Firefox上卻沒發生問題跑版問題，回頭去翻了一下Firefox過去幾版的release note，發現2019.5.21 release的Firefox 67 change list之中有這麼一項：</p><blockquote>The break-word value of the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/word-break">word-break</a> property is now supported (<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1296042">bug 1296042</a>).</blockquote><p>如圖：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K2q3km1oAN4HjjQMxzeObw.png" /></figure><p>實際在Firefox上測試過現在的確支援word-break：</p><p><a href="https://codepen.io/littleDoggy/embed/bGGxmjP">CodePen Embed - bGGxmjP</a></p><p>結論，現在Firefox也支援word-break: break-word且換行行為跟Chrome是一致的，另外在IE以及Edge上還是有些斷行行為須做特殊處理，未來有機會再來細說。</p><h4>Reference</h4><ul><li><a href="https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Releases/67#CSS">Firefox 67 for developers</a></li><li><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1296042">1296042 - Implement &quot;word-break: break-word&quot;</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3079105bb106" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mobile view height的通透世界]]></title>
            <link>https://medium.com/@ash.hana/mobile-view-height%E7%9A%84%E9%80%9A%E9%80%8F%E4%B8%96%E7%95%8C-b896ac234ba9?source=rss-b3e844bf285a------2</link>
            <guid isPermaLink="false">https://medium.com/p/b896ac234ba9</guid>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Ashley Yang]]></dc:creator>
            <pubDate>Thu, 07 Nov 2019 02:58:00 GMT</pubDate>
            <atom:updated>2019-11-07T02:58:00.409Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JIVbJXSAMNJaZQxzrCWDhw.png" /></figure><p>在mobile網頁開發時，view height一直是令人煩惱的議題，mobile browser上的navigation跟toolbar很巧妙的遮擋了可視範圍，以前能在container上用height: 100vh做解決，但在手機iOS跟Chrome app更新後這世界一切都變了，height: 100vh再也無法解決我們想解決的問題，花了點時間才找到解法，特別做個紀錄。</p><h3>直接說結論</h3><p>把100vh用fill-available取代：</p><pre>// For Edge<br>height: 100%;</pre><pre>// WebKit-based browsers will ignore this<br>height: -moz-available;</pre><pre>// Mozilla-based browsers will ignore this.<br>height: -webkit-fill-available;  </pre><pre>// For WebKit-based browsers, Edge not support this<br>height: fill-available;</pre><p>就這麼簡單！</p><p>這個做法在iOS Chrome, iOS Safari, Android Chrome, desktop Chrome, desktop Safari上實際測試過view height都能符合原預期。</p><p>有興趣可以去看看<a href="https://caniuse.com/#search=fill-available">fill-available在各platform/browser的支援度</a>。</p><h4>Reference</h4><ul><li><a href="https://stackoverflow.com/questions/37112218/css3-100vh-not-constant-in-mobile-browser">CSS3 100vh not constant in mobile browser</a></li><li><a href="https://stackoverflow.com/questions/54175400/how-to-use-height-webkit-fill-available-in-edge-browser-how-to-make-a-div-fil">How to use height: -webkit-fill-available in Edge browser? How to make a div fill the available space in Edge?</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b896ac234ba9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[當flexbox遇到height: 100%]]></title>
            <link>https://medium.com/@ash.hana/%E7%95%B6flexbox%E9%81%87%E5%88%B0height-100-242703fcaab6?source=rss-b3e844bf285a------2</link>
            <guid isPermaLink="false">https://medium.com/p/242703fcaab6</guid>
            <category><![CDATA[flexbox]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[responsive-design]]></category>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Ashley Yang]]></dc:creator>
            <pubDate>Wed, 06 Nov 2019 10:12:03 GMT</pubDate>
            <atom:updated>2019-11-06T10:17:07.538Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*dtRyxuB1XbTHKph62CCrLw.jpeg" /></figure><p>今天想來聊聊當前最方便最火紅的網頁排版方式之一：flexbox。</p><p>前陣子在專案上遇到滿有趣的問題，花了點時間去解決所以做個紀錄，以下是日常開發中常常遇到的排版方式：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*gE0zljdtpdFPC5Cdn91Y2Q.png" /></figure><p>其中要符合幾個需求：</p><ol><li>無論screen size多大，MenuBar及Header必須在頁面最上方，Footer必須在頁面最下方。</li><li>Content區塊無論內容多寡，高度需撐開至最高。</li></ol><p>根據以上需求，我們很常使用flexbox做以下的排版：</p><p>## CSS</p><pre>body, html {<br>  margin: 0;<br>  padding: 0;<br>}</pre><pre>.container {<br>  height: 100vh;<br>  display: flex;<br>  flex-flow: column;<br>}</pre><pre>.content {<br>  flex-grow: 1;<br>}</pre><pre>.inner-content {<br>  height: 100%;<br>}</pre><p>## HTML</p><pre>&lt;div class=&quot;container&quot;&gt;<br>    &lt;div class=&quot;content&quot;&gt;<br>        &lt;div class=&quot;inner-content&quot;&gt;<br>            Main content        <br>        &lt;/div&gt;<br>    &lt;/div&gt;<br>    &lt;div class=&quot;footer&quot;&gt;<br>        Footer<br>    &lt;/div&gt;<br>&lt;/div&gt;</pre><p>如以下範例：</p><p><a href="https://codepen.io/littleDoggy/embed/dyymqwg">CodePen Embed - dyymqwg</a></p><p>但是當這樣的排版方式被放在各個browser上去做檢視，有趣的事情就發生了，以下是Chrom跟Firefox上的表現，而這樣的排版結果如同我們預期：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/649/1*p3uSW6sp24rf5TxIrGvwPw.png" /></figure><p>但是在Safari上看到的卻是：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DUKa9MW0M03GJWy74KRaeA.png" /></figure><p>找了一些資料後發現這是Safari在flexbox的處理上的known issue，在nested flexbox上設置height: 100%時，高度會無法被正確的撐開至最高，原先在Chrome上也有一樣的bug但之後解掉了，只剩下Safari上有這樣的問題。</p><h3>Solution</h3><p>既然這種情況之下Safari看不懂height: 100%，那麼我們就用其他方式去解決吧！以下是用position去取代了height: 100%的做法：</p><p><a href="https://codepen.io/littleDoggy/embed/jOOzexa">CodePen Embed - jOOzexa</a></p><pre>.container {<br>  height: 100vh;<br>  display: flex;<br>  flex-flow: column;<br>}</pre><pre>.content {<br>  flex-grow: 1;<br>  position: relative;  // Add this to replace height: 100%<br>}</pre><pre>.inner-content {<br>  position: absolute;  // Add this to replace height: 100%<br>  top: 0;              // Add this to replace height: 100%<br>  bottom: 0;           // Add this to replace height: 100%<br>  left: 0;             // Add this to replace height: 100%<br>  right: 0;            // Add this to replace height: 100%<br>}</pre><p>於是我們的排版就回來啦！以上做法在各個browser上都檢視過一輪，呈現效果皆如原先預期。</p><p>Reference:</p><ul><li><a href="https://stackoverflow.com/questions/33636796/chrome-safari-not-filling-100-height-of-flex-parent">Chrome / Safari not filling 100% height of flex parent</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=242703fcaab6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[three.js的世界觀]]></title>
            <link>https://medium.com/@ash.hana/three-js%E7%9A%84%E4%B8%96%E7%95%8C%E8%A7%80-69c97901b5f0?source=rss-b3e844bf285a------2</link>
            <guid isPermaLink="false">https://medium.com/p/69c97901b5f0</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[threejs]]></category>
            <category><![CDATA[3d]]></category>
            <category><![CDATA[animation]]></category>
            <dc:creator><![CDATA[Ashley Yang]]></dc:creator>
            <pubDate>Fri, 08 Jun 2018 10:01:13 GMT</pubDate>
            <atom:updated>2018-06-08T10:01:13.588Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*jh7T7U10LzdwbYmkKYXgKQ.png" /></figure><p>前陣子有前端前輩在讀書會上分享了threeJS，去年就曾經聽人提過，正巧最近有段空閒時間就來玩一下。</p><p>在這過程之中其實滿suffer的，網路上實際運用threeJS的分享文章並不多，部分分享又有些老舊，另外如果要做出酷炫的效果對數學也要有一定的瞭解程度，不過網路上也有不少好用的JS function可供參考，那我們就開始吧！</p><p>在開始之前我想先稍微解釋一下threeJS的概念，在threeJS的世界觀中，所有的東西都是畫在一個畫布(scene)上，畫布上的任何東西都是一個物件。</p><p>例如：</p><ol><li>光線(<a href="https://threejs.org/docs/#api/lights/AmbientLight">AmbientLight</a>, <a href="https://threejs.org/docs/#api/lights/DirectionalLight">DirectionalLight</a>, etc)</li><li>3D物件(<a href="https://threejs.org/docs/#api/objects/Mesh">Mesh</a>, <a href="https://threejs.org/docs/#api/objects/Line">Line</a>, <a href="https://threejs.org/docs/#api/objects/Points">Points</a>, etc)</li></ol><p>當然你也可以把一些會需要被一起控制的東西包在一個空的3D物件(<a href="https://threejs.org/docs/#api/core/Object3D">Object3D</a>)裡面以增加效能。</p><p>例如：</p><pre>const scene = new THREE.Scene();<br>const obj3D = new THREE.Object3D();</pre><pre>// 對obj3D做定位<br>obj3D.position.x = 0;<br>obj3D.position.y = 0;<br>obj3D.position.z = 0;</pre><pre>scene.add(obj3D);</pre><pre>const mesh = createMesh();<br>obj3D.add(mesh);</pre><pre>// ==&gt; mesh 也會共用obj3D的定位設定</pre><p>大部分的3D物件都由<a href="https://threejs.org/docs/#api/core/Geometry">geometry</a>跟<a href="https://threejs.org/docs/#api/materials/Material">material</a>組成，geometry是物件的幾何形狀(eg, 立方體, 球體, 或是其他由vector組合而成幾何圖形)，material指的是物件要以何種方式呈現(appearance)，最後再以object(<a href="https://threejs.org/docs/#api/objects/Mesh">Mesh</a>, <a href="https://threejs.org/docs/#api/objects/Line">Line</a>, <a href="https://threejs.org/docs/#api/objects/Points">Points</a>, etc)組合起來，例如：</p><pre>const createMesh = () =&gt; {<br>    const geometry = new THREE.BoxBufferGeometry(1, 1, 1); <br>    const material = new THREE.MeshBasicMaterial({ <br>        color: 0xffff00 <br>    }); <br>    const mesh = new THREE.Mesh(geometry, material); <br>    return mesh;<br>};</pre><p>除了scene以外，還有另一樣東西叫做<a href="https://threejs.org/docs/#api/cameras/Camera">camera</a>，camera指的是一個控制畫布觀看視角的controller，常用到的是以下兩種：</p><ol><li><a href="https://threejs.org/docs/#api/cameras/PerspectiveCamera">PerspectiveCamera</a>：模擬實際人眼效果，距離近的物體會較大。</li><li><a href="https://threejs.org/docs/#api/cameras/OrthographicCamera">OrthographicCamera</a>：物體大小不受距離影響，維持原先定義的大小。</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/627/1*xKkUK5mt89M9ZNCn5mAsUA.png" /></figure><p>有了scene跟camera之後，就可以進行render了，因為任何畫布上的動畫及效果改變，均是需要透過不斷的render來達成，所以當你的JavaScript function執行的時間超過browser畫面重新render的時間(16ms)，或是剛好在每16ms的變化點上時，就有可能會造成畫面的閃爍，導致較差的使用者體驗，所以我們會在這裡使用<a href="https://developers.google.com/web/fundamentals/performance/rendering/optimize-javascript-execution">requestAnimationFrame</a>去更新畫面：</p><pre>const render = () =&gt; {     <br>    requestAnimationFrame(render);      <br>    cube.rotation.x += 0.1;     <br>    cube.rotation.y += 0.1;      <br>    renderer.render(scene, camera);    <br>};<br>render();</pre><p>以上幾點，就是簡單介紹threeJS的幾項重點及概念，下一篇文章會開始介紹如何用threeJS畫出你的第一顆3D地球。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=69c97901b5f0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[用”-webkit-overflow-scrolling: touch”讓你的mobile web application支援momentum-based scrolling]]></title>
            <link>https://medium.com/@ash.hana/%E7%94%A8-webkit-overflow-scrolling-touch-%E8%AE%93%E4%BD%A0%E7%9A%84mobile-web-application%E6%94%AF%E6%8F%B4momentum-based-scrolling-1efacea28611?source=rss-b3e844bf285a------2</link>
            <guid isPermaLink="false">https://medium.com/p/1efacea28611</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[touch]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[momentum]]></category>
            <dc:creator><![CDATA[Ashley Yang]]></dc:creator>
            <pubDate>Mon, 28 May 2018 06:55:06 GMT</pubDate>
            <atom:updated>2018-05-28T06:58:50.678Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*0byA6lpPKSoTLOoK4EWruA.gif" /><figcaption>momentum-based scrolling</figcaption></figure><p>通常在mobile web application的開發時，第一個在實際mobile device上遇到的問題就是使用者scroll時覺得卡卡的，這時候只要在可scroll的元素上加上-<strong>webkit-overflow-scrolling: touch;</strong>即可解決。</p><p>範例：</p><pre>Element {<br>    overflow: auto;<br>    -webkit-overflow-scrolling: touch;<br>}</pre><p><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/-webkit-overflow-scrolling">-webkit-overflow-scrolling</a>這個CSS property提供了兩個值：auto及touch，它決定可scroll元素是否支援momentum-based scrolling，iOS的網頁上預設支援momentum-based scrolling，但是我們因為實作上的需求將結構設為多層結構可scroll元素為<strong>fixed height</strong>時，momentum-based scrolling就會失效。</p><p>例如：</p><pre>&lt;!doctype html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>    &lt;head&gt;<br>        &lt;meta charset=&quot;utf-8&quot;&gt;<br>        &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt;<br>        &lt;title&gt;Without momentum-based-scrolling&lt;/title&gt;<br>        &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1, user-scalable=no&quot;&gt;<br>        &lt;style&gt;<br>            html, body {<br>                margin: 0;<br>                padding: 0;<br>            }<br>            body {<br>                width: 100vw;<br>                height: 100vh;<br>            }<br>            #app {<br>                width: 100%;<br>                <strong>height: 100%;</strong><br>                overflow: auto;<br>            }<br>            .long-div {<br>                width: 100%;<br>                height: 1200px;<br>                background: repeating-linear-gradient(red, yellow 10%, green 20%);<br>            }<br>        &lt;/style&gt;<br>    &lt;/head&gt;<br>    &lt;body&gt;<br>        &lt;div id=&#39;app&#39;&gt;<br>            &lt;div class=&quot;long-div&quot;&gt;&lt;/div&gt;<br>        &lt;/div&gt;<br>    &lt;/body&gt;<br>&lt;/html&gt;</pre><p><a href="https://codepen.io/littleDoggy/embed/XYrXKq">CodePen Embed - XYrXKq</a></p><p>無論將#app的height設為absolute value或relative value，因為直接指定了這個元素的height，所以導致momentum-based scrolling失效</p><p>但若是#app的height沒被設定或是設為auto，momentum-based scrolling仍有效：</p><pre>&lt;!doctype html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>    &lt;head&gt;<br>        &lt;meta charset=&quot;utf-8&quot;&gt;<br>        &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt;<br>        &lt;title&gt;With momentum-based-scrolling&lt;/title&gt;<br>        &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1, user-scalable=no&quot;&gt;<br>        &lt;style&gt;<br>            html, body {<br>                margin: 0;<br>                padding: 0;<br>            }<br>            body {<br>                width: 100vw;<br>                height: 100vh;<br>            }<br>            #app {<br>                width: 100%;<br>                overflow: auto;<br>            }<br>            .long-div {<br>                width: 100%;<br>                height: 1200px;<br>                background: repeating-linear-gradient(red, yellow 10%, green 20%);<br>            }<br>        &lt;/style&gt;<br>    &lt;/head&gt;<br>    &lt;body&gt;<br>        &lt;div id=&#39;app&#39;&gt;<br>            &lt;div class=&quot;long-div&quot;&gt;&lt;/div&gt;<br>        &lt;/div&gt;<br>    &lt;/body&gt;<br>&lt;/html&gt;</pre><p><a href="https://codepen.io/littleDoggy/embed/NzKxKN">CodePen Embed - NzKxKN</a></p><h4>什麼是momentum-based scrolling?</h4><p>當使用者的滑動手勢結束、手指離開螢幕後，網頁內容仍然會根據使用者滑動時的速度、力道繼續滑動並隨時間停止。</p><p>一般使用網頁上的scrollbar或滾動滑鼠滾輪時，當滾動的動作一結束，頁面滾動會立即停止在滾動動作停止的位置，但是在mobile上，為了給使用者更加良好的使用體驗，momentum-based scrolling的implement是必要的。</p><p>-webkit-overflow-scrolling的兩個值就分別代表了支援/不支援momentum-based scrolling：</p><p>auto：不支援momentum-based scrolling，當使用者結束滑動手勢、手指離開螢幕之後，頁面滾動立即停止。</p><p>touch：支援momentum-based scrolling，當使用者結束滑動手勢、手指離開螢幕之後，頁面滾動仍然會持續一下子，依據使用者滑動的速度及力道漸漸停止。</p><h4>參考資料</h4><ul><li><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/-webkit-overflow-scrolling">-webkit-overflow-scrolling</a></li><li><a href="https://css-tricks.com/snippets/css/momentum-scrolling-on-ios-overflow-elements/">Momentum Scrolling on iOS Overflow Elements | CSS-Tricks</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1efacea28611" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[“user-scalable=no”屬性被iOS Safari ignore的解決方法]]></title>
            <link>https://medium.com/@ash.hana/%E5%A6%82%E4%BD%95%E8%A7%A3%E6%B1%BA-user-scalable-no-%E5%B1%AC%E6%80%A7%E8%A2%ABios-safari-ignore-e6a0531050ba?source=rss-b3e844bf285a------2</link>
            <guid isPermaLink="false">https://medium.com/p/e6a0531050ba</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[safari]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[mobile]]></category>
            <dc:creator><![CDATA[Ashley Yang]]></dc:creator>
            <pubDate>Fri, 25 May 2018 08:46:43 GMT</pubDate>
            <atom:updated>2018-06-29T04:25:49.731Z</atom:updated>
            <content:encoded><![CDATA[<p>通常在mobile web的開發上，我們常常會在&lt;meta name=”viewport” /&gt; tag上加上user-scalable=no的屬性以避免放大縮小造成的跑版，事實上就我開發的經驗，如果排版得宜不亂用position跟flexbox，放大縮小本身並不大會造成跑版問題，但若是與mobile device橫向與直向螢幕rotate結合，每一次rotate時browser都會重新計算現在viewport要顯示的範圍，這的確會造成使用者不知道現在在哪的情形，這件事情有機會之後再來做討論。</p><p>在Mobile Safari 10.0之後的版本有一項重要的修改，預設<a href="https://developer.apple.com/library/content/releasenotes/General/WhatsNewInSafari/Articles/Safari_10_0.html">ignore了”user-scalable=no”的設定</a>，讓我們來看看這段敘述：</p><blockquote>Accessibility</blockquote><blockquote>Pinch-to-zoom is always enabled for all users. The viewport setting for user-scalable is ignored.</blockquote><p>原先在mobile瀏覽器上，使用者有以下幾種方式可以放大或縮小網頁(zoom-in/zoom-out)：</p><ol><li>Pinch to zoom-in/zoom-out</li><li>Double-tap to zoom-in/zoom-out</li></ol><p>同樣在header裡加入了&lt;meta name=”viewport” content=”width=device-width, initial-scale=1, user-scalable=no”&gt;，在iOS Chrome跟iOS Safari上的表現就不同，在iOS Chrome上無論是Double-tap跟Pinch都無法觸發網頁zoom-in/zoom-out，反之，在iOS Safari上Double-tap跟Pinch依舊會觸發網頁zoom-in/zoom-out。</p><h3>解法</h3><p>現在已經有不少解決方式，以下列出其中幾種的實際測試結果：</p><h4>以JavaScript監聽並handle touchstart/touchend事件</h4><pre>window.onload = () =&gt; {<br>  document.addEventListener(&#39;touchstart&#39;, (event) =&gt; {<br>    if (event.touches.length &gt; 1) {<br>       event.preventDefault();<br>    }<br>  });<br>  <br>  let lastTouchEnd = 0;<br>  document.addEventListener(&#39;touchend&#39;, (event) =&gt; {<br>    const now = (new Date()).getTime();<br>    if (now - lastTouchEnd &lt;= 300) {<br>      event.preventDefault();<br>    }<br>    lastTouchEnd = now;<br>  }, false);<br>}</pre><p><a href="https://codepen.io/littleDoggy/embed/GdbMeP">CodePen Embed - GdbMeP</a></p><blockquote><strong>實際測試結果：Pinch/Double-tap觸發的zoom-in/zoom-out均可成功handle</strong></blockquote><p>其中touchstart事件handle的是Pinch手勢，而touchend事件handle的則是double-tap手勢，講到double-tap就會想到mobile網頁開發時大家都會遇到的300ms延遲事件，事實上每一次使用者touch螢幕時，都會產生300ms的延遲去監聽是否觸發double-tap事件，於是就可以用這個特性來做處理，當兩次touch之間的時間差小於300ms時做event.preventDefault();直接cancel掉使用者double-tap手勢原先會觸發的zoom-in/zoom-out效果。</p><h3>[2018.6.29 Update] Passive Event Listener</h3><p>感謝網友回覆，上面這個workaround的Pinch在新版Safari仍然可以觸發zoom-in/zoom-out，剛好在公司專案也遇到的一樣的問題所以來做個update，在百思不得其解的過程之中發現了一個東西叫做<a href="https://developers.google.com/web/tools/lighthouse/audits/passive-event-listeners">Passive Event Listener</a>，這是在大概2016年新發表的特性，目的是improve scroll時的performance，其中wheel、mousewheel、touchstart 和 touchmove四個event的passive屬性default value都是true({ passive: true })，雖說是從Firefox跟Chrome開始的新東西，但是從<a href="https://caniuse.com/#feat=passive-event-listener">browser support list</a>可以看到目標browser iOS Safari已經support了這個屬性：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DP9iwB8Q22aQF2zOuz6bQg.png" /></figure><p>重點是當{ passive: true }時會導致<strong>preventDefault一點作用都沒有！</strong></p><p>所以我們必須將touchstart的passive value覆寫為false，也就是將return value改為{ passive: false }：</p><pre>window.onload = () =&gt; {<br>  document.addEventListener(&#39;touchstart&#39;, (event) =&gt; {<br>    if (event.touches.length &gt; 1) {<br>       event.preventDefault();<br>    }<br>  }, { passive: false });<br>  <br>  let lastTouchEnd = 0;<br>  document.addEventListener(&#39;touchend&#39;, (event) =&gt; {<br>    const now = (new Date()).getTime();<br>    if (now - lastTouchEnd &lt;= 300) {<br>      event.preventDefault();<br>    }<br>    lastTouchEnd = now;<br>  }, false);<br>}</pre><p>上面這個做法實際試過是可以成功handle pinch/double-tap的zoom-in/zoom-out喔！</p><h4>以CSS touch-action: manipulation禁止double-tap手勢</h4><pre>html, body {<br>  touch-action: manipulation;<br>}</pre><p><a href="https://codepen.io/littleDoggy/embed/gzNXBp">CodePen Embed - gzNXBp</a></p><blockquote><strong>實際測試結果：只可handle Double-tap手勢觸發的zoom-in/zoom-out</strong></blockquote><p>這個<a href="https://developer.mozilla.org/en-US/docs/Web/CSS/touch-action">CSS property</a>可以禁止所有不合法的手勢，針對manipulation我們擷取其中的敘述：</p><blockquote>manipulation</blockquote><blockquote>Enable panning and pinch zoom gestures, but disable additional non-standard gestures such as double-tap to zoom. Disabling double-tap to zoom removes the need for browsers to delay the generation of <strong>click</strong> events when the user taps the screen. This is an alias for &quot;<strong>pan-x pan-y pinch-zoom</strong>&quot; (which, for compatibility, is itself still valid).</blockquote><p>換言之，pinch手勢不會被禁止，但是double-tap手勢會被禁止，測試結果也是只有double-tap的手勢觸發的zoom-in/zoom-out被handle了。</p><p>依據iOS發布的內容，這項更改是為了給使用者更好的瀏覽體驗，現今的網頁通常會用響應式設計來針對不同瀏覽模式給予使用者最佳的瀏覽模式，若是無法讓使用者在瀏覽時自由放大縮小網頁，似乎也造成了使用者的不便，最好的做法還是跟設計師及客戶確認好使用者的需求並做好兩者之間的權衡了！</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e6a0531050ba" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>