Add gradient service
This commit is contained in:
parent
b850f5d621
commit
521b882798
25
projects/common/src/fm/services/gradient.service.ts
Normal file
25
projects/common/src/fm/services/gradient.service.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import {IGradientstop } from '../models/gradient'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class GradientService {
|
||||
constructor() {
|
||||
}
|
||||
|
||||
getGradientStyle(gradient:IGradientstop[],portrait:boolean = false ):any {
|
||||
let gd = '{ "background": "linear-gradient(to ' + (portrait?'bottom':'right') +',';
|
||||
for(var i=0;i<gradient.length;i++) {
|
||||
let gs = gradient[i];
|
||||
if(i>0) gd+=",";
|
||||
gd += `rgba(${gs.color.red},${gs.color.green},${gs.color.blue},${gs.color.alpha/255})`;
|
||||
gd +=` ${gs.relativestop*100}%`
|
||||
}
|
||||
gradient.forEach((gs) => {
|
||||
});
|
||||
gd+=')"}';
|
||||
|
||||
return JSON.parse(gd);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user