Ng-lazyload-image: How to create a transition effect between defaultImage and lazyLoad

Created on 26 Jan 2018  ·  3Comments  ·  Source: tjoskar/ng-lazyload-image

Hello tjoskar. Thank you for this great library! I want to ask if it is possible to create a transition effect beween the defaultImage and the lazy loaded image.

Thank you for help in advance

question

Most helpful comment

HI @AndreasSchmid1, thanks for your kind words.

You can add an animation on the image, eg.

img.ng-lazyloaded {
  animation: fadein .5s;
}
@keyframes fadein {
  from { opacity: 0; }
  to   { opacity: 1; }
}

(see "Default image" on the example page: https://tjoskar.github.io/ng-lazyload-image)

You can also add a transition between images if you create two images, one with the default image and one with the lazyloaded one. eg. https://github.com/tjoskar/ng-lazyload-image/blob/master/example/pixelated-image.component.ts (see "Pixelated image" on the example page: https://tjoskar.github.io/ng-lazyload-image)
As you may know, you can slow down the animation to get a better look at the animation (https://developers.google.com/web/tools/chrome-devtools/inspect-styles/animations).

It is also possible to add a transition on the background-image:

#image {
  height: 250px;
  width: 500px;
  transition: background-image 1s ease-out;
}
md5-a293a4af2fed33e82fce83f3f4407a8e


See this page for an example (not using ng-lazyload-image): http://jsfiddle.net/8L7775fa/4/

Let me know if you run into problems.

All 3 comments

HI @AndreasSchmid1, thanks for your kind words.

You can add an animation on the image, eg.

img.ng-lazyloaded {
  animation: fadein .5s;
}
@keyframes fadein {
  from { opacity: 0; }
  to   { opacity: 1; }
}

(see "Default image" on the example page: https://tjoskar.github.io/ng-lazyload-image)

You can also add a transition between images if you create two images, one with the default image and one with the lazyloaded one. eg. https://github.com/tjoskar/ng-lazyload-image/blob/master/example/pixelated-image.component.ts (see "Pixelated image" on the example page: https://tjoskar.github.io/ng-lazyload-image)
As you may know, you can slow down the animation to get a better look at the animation (https://developers.google.com/web/tools/chrome-devtools/inspect-styles/animations).

It is also possible to add a transition on the background-image:

#image {
  height: 250px;
  width: 500px;
  transition: background-image 1s ease-out;
}
md5-a293a4af2fed33e82fce83f3f4407a8e


See this page for an example (not using ng-lazyload-image): http://jsfiddle.net/8L7775fa/4/

Let me know if you run into problems.

Hi All,
I am developing a web application in angular 5 wherein I am using ngx bootstrap carousel and ng-lazyload-image in my html page as below.My default image loads successfully showing the spinner before the real image actually gets loaded.But the issue I am facing is my default image also increases in size as per my carousel size .Is there any way to fix the size of my default image

Below is my code------------------------

[lazyLoad]="image.carousel_image_key"
[offset]="offset">

The defaultImage is a spinner gif image(comes from my component) which I want to show to the users until my real images get loaded ( [lazyLoad]="image.carousel_image_key" ).I have fixed the size of my carousel as below in my css

mainCarouselImgLayout{

display: block;
width: 100%;
height: 400px
}
This same css gets applied on my spinner image.What I want is to keep the size of my spinner image intact and only change the carousel image height.Right now spinner image looks very big and distorted

@chandrasachin Did you find soution?
My spinner size is really big in card than my image. I want to resize the spinner image for smaller size

Was this page helpful?
0 / 5 - 0 ratings

Related issues

philipgiuliani picture philipgiuliani  ·  11Comments

vincent-cm picture vincent-cm  ·  10Comments

vugar005 picture vugar005  ·  10Comments

kmturley picture kmturley  ·  23Comments

Denis-Evseev picture Denis-Evseev  ·  28Comments