Retina Monitor’s Web Image Solution
什麼是Retina螢幕
今天來談談網頁圖片在視網膜(Retina)螢幕的顯示議題,首先必須來談談什麼是視網膜螢幕,其實他就是一種能在單位尺寸內顯示更多像素點的螢幕,且已經達到視網膜能辨識的極限,視網膜螢幕是由蘋果公司提出,賈伯斯在2010年iPhone 4的發表會中提到:「當你所拿的東西距離你10-12英寸(約25-30厘米)時,它的解析度只要達到300ppi這個『神奇數字』(每英寸300個像素點)以上,你的視網膜就無法分辨出像素點了。」
所以簡言之,視網膜螢幕比較一般非視網膜螢幕的不同處在於,能在同樣的範圍顯示更多的像素點,也就是PPI(Pixels Per Inch)比較高的螢幕,可參考下圖所示:
可以看到圖左在單位尺寸內顯示的像素點較少,圖右則能以更多的像素去呈現,在肉眼上就會覺得圖右會比較細緻。
接下來談談網頁圖片與視網膜螢幕之間的關係,先來看看同樣一張圖片在不同螢幕上顯示的效果。
當然在美觀的立場下,我們不會希望發生這樣的視覺差異,那網頁上要如何設置才可以做到讓圖形在視網膜螢幕下也能正常的顯示呢?以下提出一些解決方案:
方案1. 透過CSS針對不同的DPR (Device Pixel Ratio)設計顯示圖片
大家如果想知道自己螢幕的DPR,可以在Chrome的主控台輸入“window.devicePixelRatio”,就可以得知目前Chrome所在螢幕的DPR值。
可以觀察出來在兩個螢幕的DRP值是不同的,而透過CSS的樣式,可以針對這兩個不同的DPR設定顯示方式,可以參考下面的做法:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .logo{ width: 190px; height: 190px; background-image: url("atd-icon.jpg"); background-size: contain; } @media (-webkit-min-device-pixel-ratio: 2){ .logo{ background-image: url("atd-icon@2x.jpg"); } } </style> </head> <body> <div class="logo"></div> </body> </html> <script> </script>
這邊必須針對圖檔尺寸做個說明,其中atd-icon.jpg為190 x 190,而atd-icon@2x.jpg為380 x 380。
@media (-webkit-min-device-pixel-ratio: 2)的部分是在DPR兩倍下的Media Query。
透過這樣的方式去設定,當DPR為2的時候,螢幕上的圖片改變為atd-icon_2.jpg,剛好能夠滿足在兩倍像素狀況下的顯示需求,當然以此類推,也能去設定三倍或更高倍數下的顯示圖片。
方案二. 透過img標籤的srcset屬性
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <img src="atdIcon.jpg" srcset="atd-icon@2x.jpg x2"> </body> </html> <script> </script>
其中srcset=”atd-icon@2x.jpg 2x”表示在DPR等於2的時候要去呈現的圖片。
以上兩個方法都可以解決圖片在Retina螢幕上面顯示的問題,但也要稍微注意一下支援程度:
可以看到在IE都是無法支援的狀態,但從Edge後就開始支援,當然也可以想想目前擁有Retina螢幕的使用者,用的瀏覽器都會是哪些?說不定你不會太在乎上面那兩張圖紅色的部分。
但若是一定要有IE瀏覽器的支援,大家應該也能從上述的文章了解,我們可以透過window.devicePixelRatio的數值自行寫script進行判斷,然後再給出適合DPR的圖片,不過這邊另外推薦一個JS Library可以協助你進行這方面的判斷。
方案三. 透過Retina.js輔助進行判斷
首先到Retina.js的網站下載他們所提供的js檔,接下來至網頁引入該JS,其實網站上也有詳細的使用方法,另外檔案大小僅有約4KB並不算很大,可以參考下面的Sample Code。
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <script src="retina.min.js"></script> </head> <body> <img src="atd-icon.jpg" /> </body> </html>
可以看到在img標籤中僅使用了原始大小的atd-icon.jpg,但因為有引入retina.min.js,他會在螢幕DPR兩倍時,自動去搜尋符合倍率下的圖片,但要記得如果不加其他屬性去設定兩倍圖片的檔名,檔名就必須按照內建的規則,也就是atd-icon@2x.jpg,當然3x也依然支援,可以到官網看一下他的使用方式,但若是使用CSS設定的背景,依然沒辦法透過retina.js達到支援IE的效果。
以上三個方法提供目前在設計網頁時,對於Retina螢幕支援的做法,若在不考慮IE瀏覽器的情況下,其實方法1+方法2就已經可以解決所有情況,但若要支援IE則可以參考方法三的做法,也歡迎大家有問題可以留言進行討論。
方案四. 使用SVG圖檔
過往我們在網頁中使用的圖片僅有GIF、PNG、JPG這三種點陣圖格式,所以在高解析度(Retina)的螢幕中,我們需要輸入不同Size的圖片,來補足像素點不足的問題,現在有了另外一種解法“SVG”圖檔。
大家可以把SVG視為一種可以放在網頁上的向量圖檔,也就是說我們以前透過Illustrator或其他向量繪圖軟體(也包含Photoshop中向量工具)繪製出來的向量圖,本身放大就不會失真,但因為要放在網頁上,我們把它轉換成了前述的三種點陣格式,才導致圖檔放大後的失真,而SVG就是保留圖片原來的向量屬性,簡言之,就是把向量圖檔放在網頁上的意思。
感覺這個解決方案應該會比前幾項方便,但也有他必須要注意的地方:
- 在SVG檔案中匯入的點陣圖,在儲存成SVG時並不會被向量化,例如上圖中間的ASUS Design Logo就是匯入的點陣圖(放大後還是會模糊)。
- SVG字型可能會遺失,所以需要使用網路字型或是將文字轉成外框或形狀之後再轉存成SVG。
http://bitemup.ru
http://www.shtory72.ru/
50mg CBD 2mg THC. Speak to our highly trained customer care team and get started today. With Palm Organix wholesale CBD program you can choose from more than a dozen CBD supplements to stock including edibles, topicals and CBD for pets. cbd oil for glaucoma in dogs
esomeprazole without prescription purchase imitrex without prescription buy imitrex 50mg pills
buy nexium generic buy topiramate 100mg generic generic imitrex 50mg
http://ml500.ru
They are gluten-free, vegan, tempting, tasty, and flavorful. Plus, unlike many other CBD oils on the market, our CBD is organically grown and distributed from a federally registered facility from right here in the United States. Prime Nature CBD oil Supplement is effective in treating various skin conditions such as acne, dark circles, wrinkles, and blemishes. https://clickcannabisseeds.com/cbd-isolate-oil/
https://ladoprom.ru/
https://mile-motors.ru/
https://naxyu.net/
Chapter 25 Those outside bells rang nine times, it was already night Bai Ruyi was surprised. From 15 to 90MG, each gummy may be found in one. From anxiety to arthritis, pain relief to reducing diabetes, there are numerous applications for CBD. pure kana premium cbd gummies shark tank
http://www.graffiti-a.ru/
best mba essay writing service
buy pre written essays
website for essay writing
https://www.sextyb.com/
http://beedecor.ru
order nexium purchase esomeprazole generic sumatriptan drug
https://buysildenafil.best/# cheap sildenafil citrate
Why are you not afraid of a short life Xue Jinqiao asked. The best type of this item is CBD Gummies to take and makes some valuable body capacities to show solid strength for getting all helpful body capacities. See Table 1 for examples of products. https://cbdxpert.com/just-cbd-sleep-gummies/
http://www.1zaeb.com/
http://barcelona-nsk.ru
https://www.kon4a.com/
service to others essay
writing essays custom
who can write my essay for me
http://opeka-klin.ru
Royal energizing CBD gummies CBD gummy shapes infusing gummy bears with CBD just CBD cannabidiol gummies 250mg shark tank eagle hemp CBD gummies Royal Blend CBD Gummies Review if im sooner can i take CBD gummies charlotte web CBD gummy review unit count for bottle of CBD gummies johnny apple CBD gummies review find CBD gummies near me high line CBD gummies reputable CBD gummies brands sensei CBD gummies do CBD gummies help you stop drinking first time trying CBD gummies CBD gummy vitamins natural grocers CBD gummies lucent valley CBD gummies review CBD vegan gummies 1000mg jar potion CBD gummies review lofi CBD gummies reviews eating CBD gummies are CBD gummies proven how much do jolly CBD gummies cost Royal Blend CBD Gummies Review best CBD gummies for anxiety and stress without thc CBD gummies how long do they last CBD gummy discovery CBD gummie pucks corvallis or ceres CBD gummies hillside CBD gummies good night CBD gummies CBD gummies in houston first class CBD gummy bears dream CBD gummies george strait and CBD oil gummies CBD gummies myrtle beach are CBD gummies legal Royal Blend CBD Gummies Review CBD gummie for sleep 100 pure CBD gummies for pain CBD gummies make you feel CBD gummies have carbs CBD gummy honolulu exhale CBD fruit gummies CBD gummy ingredients copd CBD gummies for sale cherry CBD gummies costner CBD gummies Royal Blend CBD Gummies Review CBD gummies sold in florida CBD gummies cause gas CBD gummies cloud 9 CBD gummies don t feel anything pain relief CBD gummies can you bring CBD gummies on a plane usa CBD gummy hallucinations best CBD gummies for quitting smoking canada CBD gummi bears jgo CBD gummies reddit louisiana Royal Blend CBD Gummies Review CBD gummies that lower a1c are CBD gummies better than oil Royal Blend CBD Gummies Review are there CBD gummies for pain CBD bear shark gummies CBD gummies affects can you fly with CBD gummies 2021 tsa Royal Blend CBD Gummies Review CBD gummies military are gas station CBD gummies good Royal Blend CBD Gummies Review apple gummy CBD Royal Blend CBD Gummies Review are gas station CBD gummies good Royal Blend CBD Gummies Review CBD gummies dental botanical bliss CBD gummies Royal Blend CBD Gummies Review does CBD gummies help anxiety boomer CBD gummies CBD gummies buffalo buy now pay later CBD gummies Royal Blend CBD Gummies Review benefits of CBD gummy benefits of CBD gummies 25mg cat CBD gummies 20 mg CBD gummies effects Royal Blend CBD Gummies Review are CBD gummies good for depression botanical farms CBD gummies website Royal Blend CBD Gummies Review Royal Blend CBD Gummies Review Blend what are CBD gummies supposed to do 900 mg CBD gummies Premium Jane Gummies Royal Blend CBD Gummies Review banana CBD gummies allergic reaction to CBD gummies Royal Blend CBD Gummies Review are gas station CBD gummies good Royal Blend CBD Gummies Review alan shearer CBD gummies Royal Blend CBD Gummies Review Royal Blend CBD Gummies Review 5 count CBD gummies are CBD gummies worth it reddit Royal Blend CBD Gummies Review hemp bombs CBD gummies 75 mg beginners Royal Blend CBD Gummies Review Royal Blend CBD Gummies Review CBD are CBD gummies haram Royal Blend CBD Gummies Review are CBD gummies legal in pennsylvania Royal Blend CBD Gummies Review Royal Blend CBD Gummies Review Royal Blend CBD Gummies Review are CBD gummies good for nausea Royal Blend CBD Gummies Review Royal Blend CBD Gummies Review are CBD gummies legal in nj Royal Blend CBD Gummies Review Royal Blend CBD Gummies Review Royal Blend CBD Gummies Review alpha iq CBD gummies Royal Blend CBD Gummies Review are CBD gummies legal in ca Royal Blend CBD Gummies Review are CBD gummy bears illegal Royal Blend CBD Gummies Review Royal Blend CBD Gummies Review american shaman CBD gummies reviews Royal Blend CBD Gummies Review Gummies are gas station CBD gummies good Royal Blend CBD Gummies Review Royal Blend CBD Gummies Review Review Royal Blend CBD Gummies Review Royal Blend CBD Gummies Review are gas station CBD gummies good Royal Blend CBD Gummies Review are CBD gummies safe for kids Royal Blend CBD Gummies Review are CBD and hemp gummies the same thing Royal Blend CBD Gummies Review best CBD are CBD gummies better than oil Royal Blend CBD Gummies Review are CBD gummy bears safe Royal Blend CBD Gummies Review are CBD gummies sold over the counter Royal Blend CBD Gummies Review all natural CBD gummy drops Royal Blend CBD Gummies Review gummies are gas station CBD gummies good Royal Blend CBD Gummies Review for are hemp and CBD gummies the same Royal Blend CBD Gummies Review are botanical farms CBD gummies safe Royal Blend CBD Gummies Review muscle amazon prime CBD gummies for sleep Royal Blend CBD Gummies Review apex CBD gummies Royal Blend CBD Gummies Review amazon natures boost CBD gummies Royal Blend CBD Gummies Review recovery, alive americann medical cannabis gummi cares CBD plus Royal Blend CBD Gummies Review healthy choices all natural CBD gummie Royal Blend CBD Gummies Review are CBD oil gummies safe Royal Blend CBD Gummies Review CBD are CBD gummies illegal Royal Blend CBD Gummies Review gummies 2022-05-26 Royal amazon botanical farms CBD gummies Royal Blend CBD Gummies Review are CBD gummies drugs Royal Blend CBD Gummies Review Blend CBD are sun state hemp CBD gummies legal Royal Blend CBD Gummies Review Gummies Review 4000mg CBD gummies Royal Blend CBD Gummies Review. FDA Compliance. It can, therefore, help to relieve pain and may even slow disease progression. cannabis sativa seeds
https://pornoashan.com/
http://mfmm.ru