The idea is to show a low-res version of an image before the real high-resolution image has been downloaded, ideally using an img tag.
<img lowres="http://localhost/low-res-image.jpg" ng-src="http://localhost/low-res-image.jpg">
Low-res image would be visible first, and be replaced with high-res image after it has been downloaded. How can this be done? Is it possible to edit img.src attribute, or should something else (e.g. a wrapper div with background, or another temporary div) be created?
import { StyleSheet, View, Image, Button } from 'react-native' 4. Create a State named as loadingImage and set its default value as False. This State is used to show default image before loading real image and if the image loaded successfully it will display us the real image.
Whenever you load large image on the page and it's taken too much time, that time you can show loading image or you can say Placeholder image ( Html Image Placeholder ) within the same image tag. You can do this simply by using CSS. Use background property of css and set url of an loading image.
A placeholder image can communicate what type of image is intended to be shown in a particular place, and how it should layout, resize, and flow within the browser.
An image placeholder is a dummy image designed to draw attention to the need for an actual image. Wikipedia image placeholders were meant to be used on articles, especially those of living people, for the purpose of trying to obtain a freely-licensed image for them.
You'd probably want to create a directive, I'd actually have hires as the attribute, so that by default it starts with lores.
JS:
app.directive('hires', function() {
return {
restrict: 'A',
scope: { hires: '@' },
link: function(scope, element, attrs) {
element.one('load', function() {
element.attr('src', scope.hires);
});
}
};
});
HTML:
<img hires="http://localhost/hi-res-image.jpg" src="http://localhost/low-res-image.jpg" />
Because ng-src
is going to replace whatever is in src
why not use both?
<img src="img/placeholder.jpg" ng-src="{{actualone.img}} " height="150px " width="300px ">
Use normal src
for your placeholder. It will get replaced one the image for ng-src is ready.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With