如何在 livecode 中的按钮上创建鼠标悬停效果?
How to create a mouseover effect on buttons in livecode?
我一直在寻找 LiveCode 中的鼠标悬停效果,但我还没有得到它。
我想得到这样的效果 link:
Creating a Mouseover Fade Effect with jQuery
这是在 jQuery 中创建的。可以应用到LiveCode吗?
mouseEnter(后跟 mouseLeave)几乎等同于网络技术中的鼠标悬停。 LiveCode 没有内置淡入淡出效果,但您可以通过更改对象的 blendLevel 属性 来编写自己的淡入淡出效果。例如,将以下脚本添加到按钮,使其在 mouseEnter(鼠标悬停)时淡出至 80% 半透明,并在 mouseLeave 时淡出至不透明:
on mouseEnter
repeat with N = 0 to 80 step 5
set blendLevel of me to N
end repeat
end mouseEnter
on mouseLeave
repeat with N = 80 to 0 step -5
set blendLevel of me to N
end repeat
end mouseLeave
如果您不需要 fade-in/out,您可以在不编写脚本的情况下实现翻转效果。只需导入两张图片,然后将按钮的图标 属性 设置为一张图片的 id,将同一按钮的 hoverIcon 属性 设置为另一张图片的 id。
就脚本翻转效果而言,Scott 的回答很准确——您可以使用 mouseEnter 和 mouseLeave 消息来创建您想要的任何视觉变化。如果您需要 fade-in/out 效果,可以这样做:
-创建一个新按钮,使其透明,关闭showName,关闭边框。
-导入你的两张图片。假设它们被命名为 image1 和 image2。
-设置按钮的脚本如下:
on mouseEnter
set the effectRate to 500
lock screen for visual effect
set the icon of me to "image2"
unlock screen with visual effect dissolve
end mouseEnter
on mouseLeave
set the effectRate to 500
lock screen for visual effect
set the icon of me to "image1"
unlock screen with visual effect dissolve
end mouseLeave
这产生的效果几乎与您提供的 link 中的效果完全一样。您可以通过更改 effectRate 来更改溶解效果的速率;溶解速度越慢,溶解速度越快,溶解速度越快。 (effectRate 以毫秒为单位。)
on mousewithin
put random(1000)
end mousewithin
我一直在寻找 LiveCode 中的鼠标悬停效果,但我还没有得到它。 我想得到这样的效果 link: Creating a Mouseover Fade Effect with jQuery
这是在 jQuery 中创建的。可以应用到LiveCode吗?
mouseEnter(后跟 mouseLeave)几乎等同于网络技术中的鼠标悬停。 LiveCode 没有内置淡入淡出效果,但您可以通过更改对象的 blendLevel 属性 来编写自己的淡入淡出效果。例如,将以下脚本添加到按钮,使其在 mouseEnter(鼠标悬停)时淡出至 80% 半透明,并在 mouseLeave 时淡出至不透明:
on mouseEnter
repeat with N = 0 to 80 step 5
set blendLevel of me to N
end repeat
end mouseEnter
on mouseLeave
repeat with N = 80 to 0 step -5
set blendLevel of me to N
end repeat
end mouseLeave
如果您不需要 fade-in/out,您可以在不编写脚本的情况下实现翻转效果。只需导入两张图片,然后将按钮的图标 属性 设置为一张图片的 id,将同一按钮的 hoverIcon 属性 设置为另一张图片的 id。
就脚本翻转效果而言,Scott 的回答很准确——您可以使用 mouseEnter 和 mouseLeave 消息来创建您想要的任何视觉变化。如果您需要 fade-in/out 效果,可以这样做:
-创建一个新按钮,使其透明,关闭showName,关闭边框。
-导入你的两张图片。假设它们被命名为 image1 和 image2。
-设置按钮的脚本如下:
on mouseEnter
set the effectRate to 500
lock screen for visual effect
set the icon of me to "image2"
unlock screen with visual effect dissolve
end mouseEnter
on mouseLeave
set the effectRate to 500
lock screen for visual effect
set the icon of me to "image1"
unlock screen with visual effect dissolve
end mouseLeave
这产生的效果几乎与您提供的 link 中的效果完全一样。您可以通过更改 effectRate 来更改溶解效果的速率;溶解速度越慢,溶解速度越快,溶解速度越快。 (effectRate 以毫秒为单位。)
on mousewithin put random(1000) end mousewithin