TASK:#112052-修改并完善电池组件的样式以及气泡的显示
This commit is contained in:
parent
59e841f0f6
commit
b4495bc14c
|
@ -1,8 +1,8 @@
|
|||
import {css, CSSResult} from 'lit'
|
||||
export const sharedStyles: CSSResult = css`
|
||||
.holder {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
position: relative;
|
||||
width: var(--battery-width, 100%);
|
||||
height: 0;
|
||||
padding: 0;
|
||||
padding-bottom: 35.4%;
|
||||
|
@ -12,32 +12,27 @@ export const sharedStyles: CSSResult = css`
|
|||
position: absolute;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
background: linear-gradient(
|
||||
137.64deg,
|
||||
#f5f0f5 0%,
|
||||
#fafafa 20.46%,
|
||||
#d5daf2 90.45%
|
||||
);
|
||||
box-shadow: 0px 0.92vw 2.3vw rgba(0, 0, 0, 0.08);
|
||||
border-radius: 4.6vw;
|
||||
box-shadow: 0px var(--shadow-one) var(--shadow-two) rgba(0, 0, 0, 0.08);
|
||||
border-radius: var(--container-radius);
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.power {
|
||||
position: absolute;
|
||||
left: 0%;
|
||||
right: 36.01%;
|
||||
right: var(--power-right);
|
||||
top: 0%;
|
||||
bottom: 0%;
|
||||
background: linear-gradient(152.36deg, #6be4d0 8.74%, #10a775 82.29%);
|
||||
border-radius: 4.6vw 0px 0px 4.6vw;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.number {
|
||||
|
@ -45,20 +40,17 @@ export const sharedStyles: CSSResult = css`
|
|||
left: 12%;
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
font-size: 11.5vw;
|
||||
line-height: 15.18vw;
|
||||
font-size: var(--number-size);
|
||||
color: #ebc883;
|
||||
}
|
||||
|
||||
.percent {
|
||||
position: absolute;
|
||||
left: 33%;
|
||||
font-style: normal;
|
||||
left: var(--percent-left);
|
||||
font-weight: 400;
|
||||
font-size: 5.98vw;
|
||||
line-height: 5.98vw;
|
||||
font-size: var(--percent-size);
|
||||
color: #ebc883;
|
||||
padding-block-start: 6.5%;
|
||||
padding-block-start: 4.5%;
|
||||
}
|
||||
|
||||
.lightning {
|
||||
|
@ -76,8 +68,8 @@ export const sharedStyles: CSSResult = css`
|
|||
rgba(255, 255, 255, 0.5) 0%,
|
||||
rgba(255, 255, 255, 0) 100%
|
||||
);
|
||||
width: 5.52vw;
|
||||
height: 5.52vw;
|
||||
width: var(--bubbles);
|
||||
height: var(--bubbles);
|
||||
border-radius: 50%;
|
||||
opacity: 0.5;
|
||||
animation: flying 10s ease-in infinite;
|
||||
|
@ -85,24 +77,24 @@ export const sharedStyles: CSSResult = css`
|
|||
|
||||
@keyframes flying {
|
||||
0% {
|
||||
left: 0%;
|
||||
transform: translateY(0vw);
|
||||
bottom: -10%;
|
||||
transform: translateX(0vw);
|
||||
}
|
||||
25% {
|
||||
transform: translateY(5.75vw);
|
||||
transform: translateX(var(--first));
|
||||
}
|
||||
50% {
|
||||
transform: translateY(17.25vw);
|
||||
transform: translateX(var(--second));
|
||||
}
|
||||
75% {
|
||||
transform: translateY(-5.75vw);
|
||||
transform: translateX(var(--third));
|
||||
}
|
||||
88% {
|
||||
transform: translateY(-8.74vw);
|
||||
transform: translateX(var(--forth));
|
||||
}
|
||||
100% {
|
||||
left: 90%;
|
||||
transform: translateY(-11.5vw);
|
||||
bottom: 90%;
|
||||
transform: translateX(var(--fifth));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -111,44 +103,44 @@ export const sharedStyles: CSSResult = css`
|
|||
animation-delay: 0s;
|
||||
}
|
||||
.bubbles:nth-child(2) {
|
||||
width: 4.14vw;
|
||||
height: 4.14vw;
|
||||
top: 10%;
|
||||
width: var(--one);
|
||||
height: var(--one);
|
||||
left: 10%;
|
||||
animation-duration: 8s;
|
||||
animation-delay: 1s;
|
||||
}
|
||||
.bubbles:nth-child(3) {
|
||||
top: 20%;
|
||||
left: 20%;
|
||||
animation-duration: 5s;
|
||||
animation-delay: 2s;
|
||||
}
|
||||
.bubbles:nth-child(4) {
|
||||
width: 2.3vw;
|
||||
height: 2.3vw;
|
||||
width: var(--two);
|
||||
height: var(--two);
|
||||
animation-duration: 6s;
|
||||
animation-delay: 0s;
|
||||
}
|
||||
.bubbles:nth-child(5) {
|
||||
top: 40%;
|
||||
left: 40%;
|
||||
animation-duration: 7s;
|
||||
animation-delay: 2s;
|
||||
}
|
||||
.bubbles:nth-child(6) {
|
||||
top: 80%;
|
||||
width: 4.14vw;
|
||||
height: 4.14vw;
|
||||
left: 80%;
|
||||
width: var(--one);
|
||||
height: var(--one);
|
||||
animation-duration: 6s;
|
||||
animation-delay: 1s;
|
||||
}
|
||||
.bubbles:nth-child(7) {
|
||||
top: 40%;
|
||||
left: 40%;
|
||||
animation-duration: 9s;
|
||||
animation-delay: 2s;
|
||||
}
|
||||
.bubbles:nth-child(8) {
|
||||
bottom: 90%;
|
||||
width: 2.3vw;
|
||||
height: 2.3vw;
|
||||
right: 90%;
|
||||
width: var(--two);
|
||||
height: var(--two);
|
||||
animation-duration: 9s;
|
||||
animation-delay: 0s;
|
||||
}
|
||||
|
@ -174,11 +166,92 @@ export const sharedStyles: CSSResult = css`
|
|||
}
|
||||
:host([vertical]) .percent {
|
||||
transform: rotate(270deg);
|
||||
left: 9%;
|
||||
padding-right: 31%;
|
||||
padding-block-end: 30%;
|
||||
padding-right: var(--vertical-right);
|
||||
padding-block-end: var(--vertical-end);
|
||||
}
|
||||
:host([vertical]) .lightning {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
.bubbles_vertical {
|
||||
position: absolute;
|
||||
background: linear-gradient(
|
||||
180deg,
|
||||
rgba(255, 255, 255, 0.5) 0%,
|
||||
rgba(255, 255, 255, 0) 100%
|
||||
);
|
||||
width: var(--bubbles);
|
||||
height: var(--bubbles);
|
||||
border-radius: 50%;
|
||||
opacity: 0.5;
|
||||
animation: flying-vertical 10s ease-in infinite;
|
||||
}
|
||||
@keyframes flying-vertical {
|
||||
0% {
|
||||
left: 0%;
|
||||
transform: translateY(0vw);
|
||||
}
|
||||
25% {
|
||||
transform: translateY(var(--first));
|
||||
}
|
||||
50% {
|
||||
transform: translateY(var(--second));
|
||||
}
|
||||
75% {
|
||||
transform: translateY(var(--third));
|
||||
}
|
||||
88% {
|
||||
transform: translateY(var(--forth));
|
||||
}
|
||||
100% {
|
||||
left: 90%;
|
||||
transform: translateY(var(--fifth));
|
||||
}
|
||||
}
|
||||
|
||||
.bubbles_vertical:nth-child(1) {
|
||||
animation-duration: 8s;
|
||||
animation-delay: 0s;
|
||||
}
|
||||
.bubbles_vertical:nth-child(2) {
|
||||
width: var(--one);
|
||||
height: var(--one);
|
||||
top: 10%;
|
||||
animation-duration: 8s;
|
||||
animation-delay: 1s;
|
||||
}
|
||||
.bubbles_vertical:nth-child(3) {
|
||||
top: 20%;
|
||||
animation-duration: 5s;
|
||||
animation-delay: 2s;
|
||||
}
|
||||
.bubbles_vertical:nth-child(4) {
|
||||
width: var(--two);
|
||||
height: var(--two);
|
||||
animation-duration: 6s;
|
||||
animation-delay: 0s;
|
||||
}
|
||||
.bubbles_vertical:nth-child(5) {
|
||||
top: 40%;
|
||||
animation-duration: 7s;
|
||||
animation-delay: 2s;
|
||||
}
|
||||
.bubbles_vertical:nth-child(6) {
|
||||
top: 80%;
|
||||
width: var(--one);
|
||||
height: var(--one);
|
||||
animation-duration: 6s;
|
||||
animation-delay: 1s;
|
||||
}
|
||||
.bubbles_vertical:nth-child(7) {
|
||||
top: 40%;
|
||||
animation-duration: 9s;
|
||||
animation-delay: 2s;
|
||||
}
|
||||
.bubbles_vertical:nth-child(8) {
|
||||
bottom: 90%;
|
||||
width: var(--two);
|
||||
height: var(--two);
|
||||
animation-duration: 9s;
|
||||
animation-delay: 0s;
|
||||
}
|
||||
`
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import {html, LitElement, CSSResultArray, nothing} from 'lit'
|
||||
import {html, LitElement, CSSResultArray} from 'lit'
|
||||
import {customElement, property, query} from 'lit/decorators.js'
|
||||
import {sharedStyles} from './battery-styles'
|
||||
import lightning from './svg/lightning.svg'
|
||||
|
||||
@customElement('star-battery')
|
||||
export class StarBattery extends LitElement {
|
||||
|
@ -10,66 +11,93 @@ export class StarBattery extends LitElement {
|
|||
|
||||
@property({type: Boolean}) deep = false
|
||||
|
||||
@property({type: Boolean}) charge = false
|
||||
@property({type: Boolean, reflect: true}) charge = false
|
||||
|
||||
@query('.container') _container: any
|
||||
|
||||
@query('.power') _power: any
|
||||
|
||||
@query('.percent') _percent: any
|
||||
|
||||
@property({type: Boolean}) vertical = false
|
||||
@property({type: Boolean}) vertical = true
|
||||
|
||||
@property({type: Number}) percent = 22
|
||||
@property({type: Number, reflect: true}) percent = 0
|
||||
|
||||
protected firstUpdated(): void {
|
||||
if (this.charge == true) {
|
||||
var power = this._power
|
||||
power.style.right = this.percent + '%'
|
||||
this._percent.style.left = '29%'
|
||||
for (var i = 0; i < 20; i++) {
|
||||
const bubbles = document.createElement('span')
|
||||
bubbles.className = 'bubbles'
|
||||
power.append(bubbles)
|
||||
}
|
||||
static get observedAttributes() {
|
||||
return ['charge', 'percent']
|
||||
}
|
||||
|
||||
if (this.percent == 0) {
|
||||
this._percent.style.left = '32%'
|
||||
this._percent.style.paddingBlockStart = '5.5%'
|
||||
this._power.style.borderRadius = '20px'
|
||||
} else if (this.percent <= 2 && this.percent > 1) {
|
||||
this._power.style.borderRadius = '20px 9px 9.5px 20px'
|
||||
} else if (this.percent <= 1 && this.percent > 0) {
|
||||
this._power.style.borderRadius = '20px 11.5px 12px 20px'
|
||||
}
|
||||
} else {
|
||||
nothing
|
||||
attributeChangedCallback(name: string, _: any, newValue: any) {
|
||||
//console.log(name, oldValue, newValue)
|
||||
switch (name) {
|
||||
case 'charge':
|
||||
if (newValue !== null) {
|
||||
for (var i = 0; i < 20; i++) {
|
||||
const bubbles = document.createElement('span')
|
||||
bubbles.className = 'bubbles'
|
||||
this._container.append(bubbles)
|
||||
}
|
||||
} else {
|
||||
this.shadowRoot
|
||||
?.querySelectorAll('.bubbles')
|
||||
.forEach((span) => span.remove())
|
||||
}
|
||||
break
|
||||
case 'percent':
|
||||
if (newValue !== null) {
|
||||
this.percent = newValue
|
||||
this.style.setProperty('--power-right', 100 - this.percent + '%')
|
||||
if (this.percent == 0) {
|
||||
this.style.setProperty('--percent-left', '19.5%')
|
||||
this.style.setProperty('--vertical-right', '13%')
|
||||
this.style.setProperty('--vertical-end', '38.5%')
|
||||
} else if (this.percent == 100) {
|
||||
this.style.setProperty('--percent-left', '31.5%')
|
||||
this.style.setProperty('--vertical-right', '25%')
|
||||
this.style.setProperty('--vertical-end', '61.5%')
|
||||
} else {
|
||||
this.style.setProperty('--percent-left', '25.5%')
|
||||
this.style.setProperty('--vertical-right', '20%')
|
||||
this.style.setProperty('--vertical-end', '50%')
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
protected resize() {
|
||||
var width = this._container.clientWidth
|
||||
this.style.setProperty('--number-size', width / 9 + 'px')
|
||||
this.style.setProperty('--percent-size', width / 17.4 + 'px')
|
||||
this.style.setProperty('--container-radius', width / 22.6 + 'px')
|
||||
this.style.setProperty('--shadow-one', width / 113 + 'px')
|
||||
this.style.setProperty('--shadow-two', width / 45.2 + 'px')
|
||||
this.style.setProperty('--bubbles', width / 18.8 + 'px')
|
||||
this.style.setProperty('--power-other', width / 18.8 + 'px')
|
||||
this.style.setProperty('--one', width / 25 + 'px')
|
||||
this.style.setProperty('--two', width / 45.2 + 'px')
|
||||
this.style.setProperty('--first', width / 18.08 + 'px')
|
||||
this.style.setProperty('--second', width / 6.03 + 'px')
|
||||
this.style.setProperty('--third', -(width / 18.08) + 'px')
|
||||
this.style.setProperty('--forth', -(width / 11.9) + 'px')
|
||||
this.style.setProperty('--fifth', -(width / 9.04) + 'px')
|
||||
}
|
||||
|
||||
protected firstUpdated() {
|
||||
this.resize()
|
||||
window.addEventListener('resize', () => {
|
||||
this.resize()
|
||||
})
|
||||
}
|
||||
|
||||
render() {
|
||||
return html`
|
||||
<div class="holder">
|
||||
<div class="container">
|
||||
<div class="power">
|
||||
${this.charge == true
|
||||
? html`
|
||||
<span class="number">
|
||||
${this.percent == 0
|
||||
? html`
|
||||
100
|
||||
`
|
||||
: html`
|
||||
${(100 - this.percent).toPrecision(2)}
|
||||
`}
|
||||
</span>
|
||||
`
|
||||
: html`
|
||||
<span class="number">78</span>
|
||||
`}
|
||||
<span class="percent">%</span>
|
||||
</div>
|
||||
<div>
|
||||
<img src="src/assets/lightning.svg" class="lightning" />
|
||||
</div>
|
||||
<div class="power"></div>
|
||||
<span class="number">${Math.round(this.percent)}</span>
|
||||
<span class="percent">%</span>
|
||||
<img src="${lightning}" class="lightning" />
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1663655792624" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1490" width="32" height="32" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M739.2 32L160 515.2h243.2L284.8 992 864 518.4H633.6z" p-id="1491" fill="#ebc883"></path></svg>
|
After Width: | Height: | Size: 425 B |
|
@ -1,29 +1,41 @@
|
|||
import {html, LitElement, CSSResultArray} from 'lit'
|
||||
import {customElement} from 'lit/decorators.js'
|
||||
import {html, LitElement, CSSResultArray, css, PropertyValueMap} from 'lit'
|
||||
import {customElement, query} from 'lit/decorators.js'
|
||||
import {sharedStyles} from '../../../components/battery/battery-styles'
|
||||
|
||||
@customElement('panel-battery')
|
||||
export class PanelBattery extends LitElement {
|
||||
@query('#container') container!: HTMLElement
|
||||
@query('star-battery') battery!: HTMLElement
|
||||
render() {
|
||||
return html`
|
||||
<star-battery></star-battery>
|
||||
<star-battery deep></star-battery>
|
||||
<star-battery charge></star-battery>
|
||||
<star-battery charge deep></star-battery>
|
||||
<star-battery vertical></star-battery>
|
||||
<star-battery vertical deep class="location"></star-battery>
|
||||
<star-battery vertical charge class="location_charge"></star-battery>
|
||||
<star-battery
|
||||
vertical
|
||||
charge
|
||||
deep
|
||||
class="location_charge_deep"
|
||||
></star-battery>
|
||||
<div id="container">
|
||||
<star-battery></star-battery>
|
||||
</div>
|
||||
<!-- <star-battery deep></star-battery> -->
|
||||
<!-- <star-battery charge></star-battery> -->
|
||||
`
|
||||
}
|
||||
|
||||
protected firstUpdated(
|
||||
_changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>
|
||||
): void {
|
||||
;(window as any).battery = this.battery
|
||||
}
|
||||
|
||||
public static override get styles(): CSSResultArray {
|
||||
return [sharedStyles]
|
||||
return [
|
||||
sharedStyles,
|
||||
css`
|
||||
:host {
|
||||
height: 100vh;
|
||||
width: 100vw;
|
||||
}
|
||||
#container {
|
||||
height: 100vh;
|
||||
width: 100vw;
|
||||
}
|
||||
`,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue