Reputation: 1237
I have a large collection of image thumbnails stored in mongodb which I would like to render on a client using infinite scroll technique: show the first batch of images (i.e. 4 rows of them) and when user scrolls down to the last row in the batch, send a new batch of content to the client.
Is it possible to implement this using meteor?
Upvotes: 4
Views: 1404
Reputation: 3073
Use data-uri driven images.
Images.insert({data:image.toBase64()});
The template could look like:
<img id="{{_id}}" src="data:image/jpg;base64,{{{data}}}"></img>
And the output would look like:
<img id="..." src="data:image/jpg;base64,iVBO..."></img>
To create this effect:
observer-summary
) that fires whenever an image is added to the hidden container.Masonry
container, or any conventional method used to make an infinite scrolling container of images.With this procedure, you don't have to write any complicated Meteor.template.rendered
code.
Alternatively,
Meteor.autorun(function() {
var visibleImages = Session.get("newImages");
_.each(visibleImages,function(image) {
$("#container").append("<img src='" +image.data + "'></img>");
});
})
...and put documents into the newImages
session variable whenever there are new images.
Upvotes: 4