I am trying to code HTML but for some reasons, my device is unable to run CSS codes smoothly. You can check the code which is written in CodePen.
JavaScript
x
81
81
1
html {
2
height: 100%;
3
}
4
5
body {
6
background: linear-gradient(150deg, rgb(30, 30, 30) 0%, rgb(20, 20, 20) 100%);
7
}
8
9
.parent {
10
margin-left: auto;
11
margin-right: auto;
12
top: 50px;
13
width: 230px;
14
height: 90px;
15
position: relative;
16
}
17
18
#child {
19
margin-left: auto;
20
margin-right: auto;
21
position: absolute;
22
top: 0;
23
left: 0;
24
}
25
26
.button-frame {
27
margin-left: auto;
28
margin-right: auto;
29
background: none;
30
display: inline-block;
31
width: 230px;
32
height: 90px;
33
}
34
35
.path {
36
stroke-dasharray: 1000;
37
stroke-dashoffset: 1000;
38
animation: frame 4s ease-in-out;
39
animation-fill-mode: forwards;
40
}
41
42
@keyframes frame {
43
from {
44
stroke-dashoffset: 1000;
45
}
46
to {
47
stroke-dashoffset: 0;
48
}
49
}
50
51
.button {
52
margin-left: 5px;
53
margin-top: 5px;
54
display: inline-block;
55
background: none;
56
cursor: pointer;
57
text-decoration: none;
58
border: none;
59
background-color: white;
60
width: 220px;
61
height: 80px;
62
animation: butt 3s ease-in-out;
63
font-size: 24px;
64
animation-fill-mode: forwards;
65
transition: 1s;
66
}
67
68
@keyframes butt {
69
from {
70
margin-top: 30px;
71
opacity: 0%;
72
}
73
to {
74
margin-top: 5px;
75
}
76
}
77
78
button:hover {
79
font-size: 26px;
80
text-shadow: 4px 4px 2px #999999;
81
}
JavaScript
1
8
1
<div class="parent">
2
<svg class="button-frame">
3
<polygon class="path" points="0,0 200,0 230,30 230,60 230,90 30,90 0,60" style="fill:none;stroke:white;stroke-width:3px"/>
4
<text x="" y="" text-anchor="black" fill="white" font-size="">Click here<text>
5
</svg>
6
7
<div id="child"><button class="button">Figure More</button></div>
8
</div>
I have tested it on other devices, and in all of them it was smooth but the transition in my device is laggy. It feels like there is not enough fps.
I have tried to turn extensions off or try it on other browsers(including opera, edge and firefox), but the result did not change. Also, I have reactivated “Use hardware acceleration when available but it has no benefit.
I would be grateful if you help me.
Advertisement
Answer
Why don’t you use transform: translateY()
for better transitioning fps. translate
offer you a smooth transition when you want to animate the element positioning.