I would like to display a picture gallery. The picture shown would be either a portrait or a landscape, depending on the screen orientation. The pictures are landscape and portrait pictures identical, except their dimension.
I've searched SO, and so far I've found this gem.
@media only screen and (orientation: portrait){
.land{display: none;}
.port{display: inline-block;}
}
@media only screen and (orientation: landscape){
.land{display: inline-block;}
.port{display: none;}
}
I would like to append to my array of images either a .land
or .port
class, depending on their dimensions, so that the approriate picture(s) are shown, depening on the orientation of the screen.
How would I do this?
If I can provide any additional information, let me know.
Thank you
Edit: I would like to thank everyone for the examples shown so far. What I have not mentioned before (and I guess I should have) is that my gallery has a next and a previous button. The images change constantly and as far as I understand, changing the class of the picture shown will not change the image shown, it will just change a class which does not help in this case.
Or am I missing something vital here?
Wouldn't it make more sense to have two arrays and on orientation change just change the array from which the picture is taken?
Or maybe have an object, something like this
let pictures = [
{
port: './imgs/port-pic1.jpg',
land: './imgs/land-pic1.jpg'
},{
port: './imgs/port-pic2.jpg',
land: './imgs/land-pic2.jpg'
}
]