-
Notifications
You must be signed in to change notification settings - Fork 142
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
[feature-request]: Allow background-image with gradients #495
Comments
Hi @GregOnNet, This is a great idea. I see a few different options here:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { LazyLoadImageModule, IntersectionObserverHooks, Attributes, LAZYLOAD_IMAGE_HOOKS } from 'ng-lazyload-image';
import { AppComponent } from './app.component';
export class LazyLoadImageHooks extends IntersectionObserverHooks {
setLoadedImage(att: Attributes) {
if (att.element.dataset.backgroundWithGradient) {
att.element.style.backgroundImage = att.element.dataset.backgroundWithGradient;
} else {
super.setLoadedImage(att);
}
}
}
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, LazyLoadImageModule],
providers: [{ provide: LAZYLOAD_IMAGE_HOOKS, useClass: LazyLoadImageHooks }],
bootstrap: [AppComponent],
})
export class MyAppModule {} And then using the following template: I do however think this should be supported out of the box but I'm not sure how. There is an old, open, PR where we have discussed similar issues. |
Hi, thanks for the hint. Concerning the API. I agree it would be nice to have this feature out-of-the-box. <div [lazyBackground]="imageUrl" [lazyBackroundGradient]="{
position: "below"|"above",
definition: "linear-gradient(rgba(0,0,0,0.45), rgba(0,0,0,0.7))"
}"> |
I think it will be hard to implement this so it scales. What if I want to add background: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 1)), url('...') no-repeat; And I believe it exists more edge cases. Maybe we can use a template, something like this: <div [lazyBackground]="imageUrl" [styleToApply]="linear-gradient(rgba(0,0,0,0.45), rgba(0,0,0,0.7)), url('$IMAGE_URL$')"> But should that style also be used for the default/error-image? |
Hello @tjoskar,
thank you for providing this neat library.
Currently, I try to do something like this:
TEMPLATE
COMPONENT
Of course, this fails, since
[lazyload]
expects an image URL.It would help me if I could do something like shown above in order to define a gradient on top of the loaded image.
What do you think about it?
The text was updated successfully, but these errors were encountered: