JQuery animate动画应用示例

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style type="text/css"> .btns input{ width: 100px; height: 40px; background-color: grey; border: 0; } .btns .current{ background-color: gold; } .cons .slides div{ width: 500px; height: 300px; background-color: gold; /*display: none;!*整体都不显示了*!*/ text-align: center; line-height: 300px; font-size: 30px; float: left;/*把三个div由隐藏改为浮动*/ } .cons{ width: 500px; height: 300px; overflow: hidden; /*超过cons的slide隐藏*/ position: relative;/*相对于slide绝对定位*/ } .slides{ width: 1500px; height: 300px; /*把slide加长*/ position: absolute;/*相对于cons相对定位*/ } .cons .active{ display: block; } </style> <script src="https://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> <script type="text/javascript"> $(function () { var $btn=$('.btns input'); var $slides=$('.cons .slides'); // alert($btn.length); // alert($div.length); $btn.click(function () { // 我点击哪一个按钮,$(this)就指的是谁,而this //指的是原生的,$(this)指的是JQuery的 // $(this).siblings().removeClass('current'); // $(this).addClass('current');//可以用链式调用 $(this).addClass('current').siblings().removeClass('current'); // var num=$(this).index(); // $div.eq($(this).index()).addClass('active').sibling().removeClass('active'); $slides.animate({left:(-500*$(this).index())}); }) }) </script> </head> <body> <div> <input type="button" value="01"> <input type="button" value="02"> <input type="button" value="03"> </div> <div> <div> <div >选项卡1的内容</div> <div>选项卡2的内容</div> <div>选项卡3的内容</div> </div> </div> </body> </html>

将slides下面的div由隐藏改为浮动,将cons设置成绝对定位,将slides改为相对定位。超过cons的slides隐藏。
点击事件发生之后,相对定位改变。

animate动画

$div=$('#div1'); $div.animate({ width:300, height:300 },1000,'swing',function () { alert('done'); })

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script src="https://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> <script type="text/javascript"> $(function () { $box=$('.box'); $box.animate({ width:300, height:300 },1000,'swing',function () { alert('done'); }) }) </script> <style type="text/css"> .box{ width: 100px; height: 100px; background-color: gold; } </style> </head> <body> <div></div> </body> </html>

用animate动画改变box大小,完成之后用回调函数弹出done

感兴趣的朋友可以使用如下工具测试上述代码运行效果:

在线HTML/CSS/JavaScript代码运行工具:

在线HTML/CSS/JavaScript前端代码调试运行工具:

更多关于jQuery相关内容还可查看本站专题:《jQuery动画与特效用法总结》、《jQuery切换特效与技巧总结》、《jQuery扩展技巧总结》、《jQuery常用插件及用法总结》、《jQuery拖拽特效与技巧总结》、《jQuery表格(table)操作技巧汇总》、《jQuery常见经典特效汇总》及《jquery选择器用法总结

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/7901cfaeda02f000466c11a52e1cdbff.html