-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Horizontal on desktop und vertical on smartphone #222
Comments
We use lazyload in a view that let's the user switch between horizontal (row across the top), vertical (column on the left), and full page (rows and columns that fill the page). This is obviously more than you need but hopefully you can glean the pieces you need from this. The following code snippets are copied from our source but I've edited them in places to attempt to simplify the example. My apologies if any of this is non-functional. Our HTML has an outer <div id='MyThumbnailDiv'>
<div class='thumbImgDiv'><img src='Images/spinner.gif' class='thumbnail' data-original='Images/MyImage1.jpg' /></div>
</div> We are doing some other things like captions for the images and I don't recall if the Our CSS is as follows: .thumbnailViewerHorz
{
height: 150px;
overflow-x: auto;
overflow-y: hidden;
white-space: nowrap;
}
.thumbnailViewerVert
{
width: 150px;
overflow-x: hidden;
overflow-y: auto;
white-space: normal;
}
.thumbnailViewerFull
{
overflow-x: hidden;
overflow-y: auto;
white-space: normal;
}
.thumbImgDiv
{
text-align: center;
display: inline-block;
width: 100px;
vertical-align: bottom;
padding: 10px;
margin: 1px;
}
.thumbnail
{
margin-left: 0px;
margin-right: 0px;
} Finally we use JavaScript (jQuery) to change the class and height: function Vertical()
{
$('#MyThumbnailDiv')[0].className = 'thumbnailViewerVert';
$('#MyThumbnailDiv').css('height', '100%');
}
function Horizontal()
{
$('#MyThumbnailDiv')[0].className = 'thumbnailViewerHorz';
$('#MyThumbnailDiv').css('height', '');
}
function FullPage()
{
$('#MyThumbnailDiv')[0].className = 'thumbnailViewerFull';
$('#MyThumbnailDiv').css('height', '100%');
} Now, having been dumped all of that on you what you may need is to simply set different attributes for a ThumbnailViewer class using <div class='ThumbnailViewer'>
<img src='Images/spinner.gif' class='thumbnail' data-original='Images/MyImage1.jpg' />
</div> @media screen and (min-width: 601px)
{
/* Horizontal */
height: 150px;
white-space: nowrap;
}
@media screen and (max-width: 600px)
{
/* Vertical */
width: 150px;
white-space: normal;
} This would mean no JavaScript and obviously simplified CSS. |
Hi @montrothstein , thank you for your detailed answer. I really appreciate that. I have a slightly different HTML structure and don't get your solution to work: <div class="gallery">
<ul>
<li>
<img class="lazy" data-original=" " width="750" height="500">
</li>
</ul>
</div> |
The CSS I gave you was missing the class selector, and therefore wouldn't apply. I couldn't get your Init LazyLoad with your gallery container: $(document).ready(function() {
$("img.lazy").lazyload({
container: $('.gallery')
});
}); Apply different CSS based on screen width. This is easy to test simply by resizing your desktop browser window. Note that the /* Horizontal */
@media screen and (min-width: 601px)
{
.gallery
{
height: 500px;
}
img
{
width: 750px;
height: 500px;
}
}
/* Vertical */
@media screen and (max-width: 600px)
{
.gallery
{
width: 400px;
}
img
{
width: 400px;
height: 267px;
}
} The HTML is then very simple. <div class="gallery">
<img class="lazy" data-original=" ">
<img class="lazy" data-original=" ">
</div> Note there is no need for a If you are unable to remove the |
I wonder how I should use lazyload when the layout changes.
I have a horizontal image gallery on the desktop. And on Smartphone (under 500px) I have a vertical arrangement of images. How can I use lazyload to solve both circumstances. Currently it works for me only in the horizontal variant.
Maybe someone has a tip for me :)
Thank you
The text was updated successfully, but these errors were encountered: