我有一个网站,这是其代码的一部分:
c = ft.Container(
ft.Text(value="Admin Page", color="cyan", size=50),
border_radius = 10,
offset = ft.transform.Offset(0, 0),
scale=ft.transform.Scale(scale=2),
animate_offset = ft.animation.Animation(1500, ft.AnimationCurve.FAST_OUT_SLOWIN),
)
def animate(e):
a = 2
c.offset = ft.transform.Offset(0, -4)
for i in range(100):
c.scale = ft.transform.Scale(a)
time.sleep(0.015)
c.update()
a -= 0.01
c.update()
page.add(
c,
ft.ElevatedButton("Login", on_click=animate),
)
我需要按钮在单击时消失,或者动画在页面加载时出现,而不是在单击按钮时出现。预先感谢,抱歉英语不好。
我尝试向动画函数添加透明度值,以便稍后可以返回它,但它不起作用。
试试这个:
import time
# Function to animate the container
def animate():
a = 2
c.offset = ft.transform.Offset(0, -4)
for i in range(100):
c.scale = ft.transform.Scale(a)
time.sleep(0.015)
c.update()
a -= 0.01
c.update()
# Function to hide the button when clicked
def hide_button(e):
page.remove(button)
# Create the container
c = ft.Container(
ft.Text(value="Admin Page", color="cyan", size=50),
border_radius=10,
offset=ft.transform.Offset(0, 0),
scale=ft.transform.Scale(scale=2),
animate_offset=ft.animation.Animation(1500, ft.AnimationCurve.FAST_OUT_SLOWIN),
)
# Create the button
button = ft.ElevatedButton("Login", on_click=hide_button)
# Add the container and button to the page
page.add(c, button)
# Trigger the animation when the page loads
animate()
单击时按钮消失: 单击按钮时只需隐藏按钮即可。
页面加载时的动画:页面加载后即可触发动画。