I'm working on a gallery. I would like to show portrait oriented picutres to mobile phone users and landscape oriented pictures to everyone else (tablets, laptops etc).
What I currently have is:
var maxW = window.screen.availWidth * window.devicePixelRatio;
if (maxW <= 767){
galleryImages = portraitImages;
}else{
galleryImages = landscapeImages;
};
var portraitImages = [ 'https://static.photocdn.pt/images/articles/2016-7/landscape-comp/iStock_000058793850_Medium.jpg',
'https://keyassets.timeincuk.net/inspirewp/live/wp-content/uploads/sites/12/2016/05/AP_Portrait_Landscapes_Stu_Meech-5.jpg',
'https://keyassets.timeincuk.net/inspirewp/live/wp-content/uploads/sites/12/2016/05/AP_Portrait_Landscapes_Stu_Meech-16.jpg',
'https://static.photocdn.pt/images/articles/2016-7/landscape-comp/iStock_000062009934_Medium.jpg']
var landscapeImages = ['https://images.unsplash.com/photo-1506744038136-46273834b3fb?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjM3Njd9&w=1000&q=80',
'https://images.unsplash.com/photo-1506260408121-e353d10b87c7?ixlib=rb-1.2.1&w=1000&q=80',
'https://www.tom-archer.com/wp-content/uploads/2017/03/landscape-photography-tom-archer-4.jpg',
'https://s.yimg.com/uu/api/res/1.2/DdytqdFTgtQuxVrHLDdmjQ--~B/aD03MTY7dz0xMDgwO3NtPTE7YXBwaWQ9eXRhY2h5b24-/https://media-mbst-pub-ue1.s3.amazonaws.com/creatr-uploaded-images/2019-11/7b5b5330-112b-11ea-a77f-7c019be7ecae',
'https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/hbx030117buzz14-1550595844.jpg']
Now, lets say, the smallest "resolution" for tablets is 768x1024. When I go to Dev Tools, input 768x1024 in resolution and call alert("MaxW: " + maxW + ",\nMaxH : " + maxH);
I get MaxW: 1536, MaxH: 2048 which is caused by the device-pixel ratio.
So, my question, how would I calculate the max screen size for a mobile phone, taking into consideration the device-pixel ratio.
I can't very well say "show picture gallery if max-device width is 2048", since some computer monitors have worse resolution.
I hope I'm getting my meaning across. If I can provide any additional information / explenation, let me know.
Thank you for the help.