源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

通过jquery实现页面的动画效果(实例代码)

  • 时间:2020-09-03 01:12 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:通过jquery实现页面的动画效果(实例代码)
有很多函数可以用来实现动画效果,其中animate函数为最为常见的函数之一。以下为对该函数使用方式的简要介绍。 [b]animate函数基本形式[/b] 通过animate实现动画效果的基本形式为: $(selector).animate({params},speed,callback); 其中{params}为必须项,它是一个对象,指明了我们希望指定元素通过动画效果运行后,其所具有的的CSS样式,speed和callback则皆为可选项,其中speed指明了动画运行的速度,其值可为数值类型(如1000表示动画在1s内变为params指定样式)、slow以及fast。callback指明动画运行结束后要执行的函数。 [b]代码示例: [/b]
<!DOCTYPE html>
<html>
<head>
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js">
</script>
<script> 
$(document).ready(function(){
 $("button").click(function(){
  $("div").animate({
   left:'250px',
   opacity:'0.5',
   height:'150px',
   width:'150px'
  });
 });
});
</script> 
</head>
 
<body>
<button>Start Animation</button>
<p>By default, all HTML elements have a static position, and cannot be moved. To manipulate the position, remember to first set the CSS position property of the element to relative, fixed, or absolute!</p>
<div style="background:#98bf21;height:100px;width:100px;position:absolute;">
</div>

</body>
</html> 
[b]{params}对象中的变量的多种赋值形式[/b] 关于{params}对象中的变量,可以通过如下形式赋值。 [b]绝对值形式[/b] 在上文给出的代码示例便是通过绝对值形式来赋值params对象的 [b]相对值形式[/b] 比如说在变量值前面加上“+”“-”等。 [b]代码示例: [/b]
<script> 
$(document).ready(function(){
 $("button").click(function(){
  $("div").animate({
   left:'250px',
   height:'+=150px',
   width:'+=150px'
  });
 });
});
</script> 
[b]show、hide以及toogle[/b] params对象的变量值,我们同样可以赋值为以上三个值,比如下面的代码,其作用便是使div标签内容消失。
$("button").click(function(){
 $("div").animate({
  height:'toggle'
 });
}); 

以上这篇通过jquery实现页面的动画效果(实例代码)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持编程素材网。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部