jQuery效果
jQuery显示和隐藏动画
<script>
$(function(){
$('button').eq(0).click(function(){
$('div').show(1000,function(){
alert('xxxx')
});
})
$('button').eq(1).click(function(){
$('div').hide(1000,function(){
alert('啊啊啊啊')
});
})
$('button').eq(2).click(function(){
$('div').toggle(1000);
$('div').toggle(1000,function(){
alert('呜呜呜呜');
});
})
})
</script>
<body>
<button>显示
</button>
<button>隐藏
</button>
<button>切换
</button>
<div></div>
</body>
jQuery展开和收起动画
<script>
$(function(){
$('button').eq(0).click(function(){
$('div').slideDown(1000,function(){
alert('xxxx')
});
})
$('button').eq(1).click(function(){
$('div').slideUp(1000,function(){
alert('xxxx')
});
})
$('button').eq(2).click(function(){
$('div').slideToggle(1000,function(){
alert('xxxx')
});
})
})
</script>
<body>
<button>显示
</button>
<button>隐藏
</button>
<button>切换
</button>
<div></div>
</body>
jQuery children方法
jQuery中的children方法是找指定元素的子元素 在括号中传入参数为找跟参数相同名字的子元素
元素
.children('字符串值,包含匹配元素的选择器表达式。');
jQuery stop方法
stop方法直接结束除了当前的动画之前的所有动画 防止用户快速移动鼠标触发多个动画 逐个执行 带来的操作延迟
stop不管之前的动画有没有执行完还是根本没执行 都直接停掉 移除掉
元素.stop();
jQuery淡入淡出动画
<script>
$(function(){
$('button').eq(0).click(function(){
$('div').fadeIn(1000,function(){
alert('x')
})
});
$('button').eq(1).click(function(){
$('div').fadeOut(1000,function(){
alert('y')
})
});
$('button').eq(2).click(function(){
$('div').fadeToggle(1000,function(){
alert('a')
})
});
$('button').eq(3).click(function(){
$('div').fadeTo(1000,0.5,function(){
alert('a')
})
});
})
</script>
<body>
<button>淡入
</button>
<button>淡出
</button>
<button>切换
</button>
<button>淡入到
</button>
<div></div>
</body>
jQuery自定义效果动画
animate方法
<script>
$(function(){
$('button').eq(0).click(function(){
$('.one').animate({marginLeft:500},5000,function(){
alert('动画执行完毕');
});
$('.two').animate({marginLeft:500},5000,'linear',function(){
alert('动画执行完毕');
});
})
$('button').eq(1).click(function(){
$('.one').animate({width:"+=100"},1000,function(){
alert('动画执行完毕');
});
})
$('button').eq(2).click(function(){
$('.one').animate({width:'hide'},1000,function(){
alert('动画执行完毕');
});
})
})
</script>
<body>
<button>属性操作
</button>
<button>累加属性
</button>
<button>关键字
</button>
<div class="one"></div>
<div class="two"></div>
</body>
jQuery的stop和delay方法
<script
>
$(function(){
$('button').eq(0).click(function(){
$('.one').animate({width
:500},1000).animate({height
:500},1000).animate({height
:100},1000).animate({width
:100},1000);
})
$('button').eq(1).click(function(){
$('div').stop(false,false);
})
})
</script
>
<body
>
<button
>开始动画
</button
>
<button
>停止动画
</button
>
<div
class="one"></div
>
<div
class="two"></div
>