使用animate()从右向左滑动div [英] Slide a div from right to left using animate()
本文介绍了使用animate()从右向左滑动div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望div '.whole'
进行动画处理(从右向左滑动)
I want a div '.whole'
to animate (slide from right to left)
jQuery
$('#menu').click(function() {
$('.whole').toggleClass('r2');
$('#slideMenu').toggle();
});
.r2 { right: 200px }
我不能正确使用animate()函数.
I am not able to use the function animate() properly.
推荐答案
这应该有效:
$('#menu').click(function(event) {
event.preventDefault(); // because it is an anchor element
$('.whole').animate({
right: '200px'
});
$('#slideMenu').toggle();
});
但是您的position
属性应该已经在CSS中设置了,否则可能无法完全获得所需的内容.
But your position
property should already be set in CSS or you might not get exactly what you need.
说明:该函数采用属性的JS对象,如下所示:
To explain: the function takes a JS object of properties, like this:
{
right: '200px',
somethingElse: 'value',
myboolean: true
}
您还可以将其分配给var并将其传递给animate
:
you can also assign this to a var and pass it to animate
:
var cssProperties = { right: '200px' }
$('#menu').click(function() {
$('.whole').animate(cssProperties);
});
您可以在文档中通过可读的其他论点.
You can pass other arguements as readable in the documentation.
这篇关于使用animate()从右向左滑动div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文