YUI 动画实用程序的 onmousedown 和 onmouseup
我的目标是使用 YUI 动画实用程序创建一个动画,该实用程序执行以下操作:
- 用户单击按钮。 元素开始从 A 点移动到 B 点
- 用户释放光标或将光标移离按钮。 元素停止并停留在当前位置。
- 用户再次单击该按钮。 该元素从当前位置向 B 点进行动画处理。
我看不到用 YUI 执行此操作的方法。 所有示例都显示一个按钮,单击该按钮会导致发生设定的动画序列(没有开始和停止)。
我怎样才能用 YUI 做到这一点?
伊勒布尔的回答有效! 这是完整的工作代码:
<style>
#menu_holder {
height:100px;
width:150px;
overflow:auto;
}
</style>
<div id="menu_holder">
<ul id="menu">
<li><a href="#">Example Link</a></li>
<li><a href="#">Example Link</a></li>
<li><a href="#">Example Link</a></li>
</ul>
</div>
<br><br>
<button id="scroll-up">Scoll Up</button><br>
<button id="scroll-down">Scoll Down</button>
<script>
(function() {
// find menu height
var region = YAHOO.util.Dom.getRegion('menu');
var elmHeight = region.bottom - region.top;
// anim up
var anim_up_attributes = {
scroll: { to: [0, elmHeight*-1] }
};
var anim_up = new YAHOO.util.Scroll('menu_holder', anim_up_attributes);
YAHOO.util.Event.on('scroll-up', 'mousedown', function() {
anim_up.animate();
});
YAHOO.util.Event.on('scroll-up', 'mouseup', function() {
anim_up.stop();
});
YAHOO.util.Event.on('scroll-up', 'mouseout', function() {
anim_up.stop();
});
// anim down
var anim_down_attributes = {
scroll: { to: [0, elmHeight] }
};
var anim_down = new YAHOO.util.Scroll('menu_holder', anim_down_attributes);
YAHOO.util.Event.on('scroll-down', 'mousedown', function() {
anim_down.animate();
});
YAHOO.util.Event.on('scroll-down', 'mouseup', function() {
anim_down.stop();
});
YAHOO.util.Event.on('scroll-down', 'mouseout', function() {
anim_down.stop();
});
})();
</script>
My goal is to create an animation with the YUI Animation Utility that does the following:
- The user clicks a button. An element begins moving from point A to point B
- The user releases or moves the the cursor off the button. The element stops and stays in its current position.
- The user clicks the button again. The element animates from its current position toward point B.
I can't see a way to do this with YUI. All the examples show a button that, when clicked, causes a set animation sequence to occur (no starting and stopping).
How can I do this with YUI?
Ylebre's answer worked! Here is the full, working code:
<style>
#menu_holder {
height:100px;
width:150px;
overflow:auto;
}
</style>
<div id="menu_holder">
<ul id="menu">
<li><a href="#">Example Link</a></li>
<li><a href="#">Example Link</a></li>
<li><a href="#">Example Link</a></li>
</ul>
</div>
<br><br>
<button id="scroll-up">Scoll Up</button><br>
<button id="scroll-down">Scoll Down</button>
<script>
(function() {
// find menu height
var region = YAHOO.util.Dom.getRegion('menu');
var elmHeight = region.bottom - region.top;
// anim up
var anim_up_attributes = {
scroll: { to: [0, elmHeight*-1] }
};
var anim_up = new YAHOO.util.Scroll('menu_holder', anim_up_attributes);
YAHOO.util.Event.on('scroll-up', 'mousedown', function() {
anim_up.animate();
});
YAHOO.util.Event.on('scroll-up', 'mouseup', function() {
anim_up.stop();
});
YAHOO.util.Event.on('scroll-up', 'mouseout', function() {
anim_up.stop();
});
// anim down
var anim_down_attributes = {
scroll: { to: [0, elmHeight] }
};
var anim_down = new YAHOO.util.Scroll('menu_holder', anim_down_attributes);
YAHOO.util.Event.on('scroll-down', 'mousedown', function() {
anim_down.animate();
});
YAHOO.util.Event.on('scroll-down', 'mouseup', function() {
anim_down.stop();
});
YAHOO.util.Event.on('scroll-down', 'mouseout', function() {
anim_down.stop();
});
})();
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我正确地阅读了文档:
如果将动画分配给变量:
那么您可以调用
来停止动画。
希望这可以帮助!
If I read the docs correctly:
If you assign the animation to a variable:
Then you can call
to stop the animation.
Hope this helps!