我需要一个div标签在屏幕右侧滑出,如何使用jQuery获得这种效果?我一直在看这里:http://api.jquery.com/category/effects/sliding/而且这似乎不是我要找的......
最佳答案
如果您愿意包含 jQuery UI库,除了jQuery本身,那么你可以简单地使用hide()
, with additional arguments ,如下:
$(document).ready(
function(){
$('#slider').click(
function(){
$(this).hide('slide',{direction:'right'},1000);
});
});
<小时/>
无需使用 jQuery UI,您只需使用 animate()
即可实现您的目标:
$(document).ready(
function(){
$('#slider').click(
function(){
$(this)
.animate(
{
'margin-left':'1000px'
// to move it towards the right and, probably, off-screen.
},1000,
function(){
$(this).slideUp('fast');
// once it's finished moving to the right, just
// removes the the element from the display, you could use
// `remove()` instead, or whatever.
}
);
});
});
如果您选择使用 jQuery UI,那么我建议您链接到 Google 托管的代码,地址为:https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js
关于jQuery .slideRight 效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4229422/