html:

        <button>点击我</button>
<p>如果你想在一个涉及动画的函数之后来执行语句,请使用callback函数</p> <div class="panel"></div>
<div class="content"></div>

css部分:

注意:使用animate函数时,为了能够影响元素的 top bottom left right 属性值,需先将position属性值设置为 relative 或者 absolute 

            .panel {
width: 100px;
height: 100px;
border: 1px solid #0050d0;
background: red;
cursor: pointer;
position: relative;
} .content {
width: 100px;
height: 100px;
margin-top: 20px;
background: green;
}

如果在500之前加上 += 或 -= 代表在当前位置递增或者递减 

        $(".panel").click(function() {
$(this).animate({left: "+=500"},3000);//递增
})

同时执行多个动画

$(this).animate({left: "500", top: "200"},3000);

按顺序执行动画 -- 动画队列

 $(this).animate({left: "500"},3000);
$(this).animate({top: "200"},3000);

以上可改为 链式写法

$(this).animate({left: "500px"},3000).animate({top: "200px"}, 3000);

综合动画
 透明度可以用小数,用百分数无效

$(this).animate({left: "500px", height: "200px", opacity: "0.5"},3000).animate({top: "200px", width: "200px"},3000).fadeOut("slow");

给hover 事件添加 stop() 方法 可解决移入移出动作过快 导致光标动作与动画效果不一致的问题
注意: 移入移出都需要添加stop()

$(".panel").hover(function() {
$(this).stop().animate({height: "150",width: "300"},3000)
},function(){
$(this).stop().animate({height: "22",width: "60"},3000)
})

当遇到的是组合动画的时候

                    $(".panel").hover(function() {
$(this).stop()
.animate({height: "150"},3000)//如果此时光标移出 .animate({width: "300"},3000)//执行这个动画 而不是下面移出的动画
},function(){
$(this).stop()
.animate({height: "22"},3000)
.animate({width: "60"},3000)
})

把stop()第一个参数设置为true ,可以解决上面的问题,跳过width为300的样式改变 执行鼠标移出事件

                    $(".panel").hover(function() {
$(this).stop(true)
.animate({height: "150"},3000)//如果此时光标移出 .animate({width: "300"},3000)//执行下面移出的动画
},function(){
$(this).stop(true)
.animate({height: "22"},3000)
.animate({width: "60"},3000)
})

如果stop()第二个参数也设置为true的时候,可以直接到达结束时候的状态

  

  

  

  

  

  

  

 

关于JQuery animate()方法的更多相关文章

  1. jQuery animate方法开发极客标签Logo动画融合效果

    在线演示 本地下载 jQuery的animate方法基础使用,演示如何生成一个jQuery animate方法开发极客标签Logo动画融合效果 相关代码录播:jQuery animate方法开发极客标 ...

  2. jquery animate()方法 语法

    jquery animate()方法 语法 作用:animate() 方法执行 CSS 属性集的自定义动画.该方法通过CSS样式将元素从一个状态改变为另一个状态.CSS属性值是逐渐改变的,这样就可以创 ...

  3. jQuery animate() 方法

    定义和用法 animate() 方法执行 CSS 属性集的自定义动画. 该方法通过 CSS 样式将元素从一个状态改变为另一个状态.CSS属性值是逐渐改变的,这样就可以创建动画效果. 只有数字值可创建动 ...

  4. jquery animate()方法使用的注意事项

    当使用 animate() 时,必须使用 Camel 标记法书写所有的属性名,比如,必须使用 paddingLeft 而不是 padding-left,使用 marginRight 而不是 margi ...

  5. jQuery 效果 - 动画 animate() 方法

    我们先看一个demo <!DOCTYPE html> <html> <head> <script src="/jquery/jquery-1.11. ...

  6. jQuery animate()动画效果

    1.jQuery动画效果 jQuery animate()方法用于创建自定义动画 $(selector).animate({params},speed,callback); //必需的 params ...

  7. 使用jQuery的animate方法制作滑动菜单

    周末看Ziv小威的博客<制作滑动条菜单,如何延时处理滑动效果,避免动画卡顿>,参见地址:http://www.cnblogs.com/zivxiaowei/p/3462964.html.是 ...

  8. Jquery动画方法 jquery.animate()

    目前在学习Oracle数据库,由于刚接触,学校让练习练习HTML内容,就想起了老师以前提起过的animate方法 animate是jquery的一个方法,这个方法主要功能是能实现比较平滑的动态效果,所 ...

  9. jQuery 效果 - animate() 方法

    http://www.w3school.com.cn/jquery/effect_animate.asp 实例 改变 "div" 元素的高度: $(".btn1" ...

随机推荐

  1. docker搭建tomcat环境

    1.拉取镜像 docker pull tomcat 2.运行容器 docker run --name tomcat -p : -v /data/tomcat/test:/usr/local/tomca ...

  2. [HDU4089]Activation(概率DP)

    HDU4089 题意:有n个人排队等着在官网上激活游戏.Tomato排在第m个. 对于队列中的第一个人.有一下情况: 1.激活失败,留在队列中等待下一次激活(概率为p1) 2.失去连接,出队列,然后排 ...

  3. POJ_2886 Who Gets the Most Candies? 【二分+树状数组】

    一.题目 POJ2886 二.分析 这个题目吧,开始没读懂,做的时候也没懂,WA的时候懂了.假设是第p个出圈的人有一个对应的因子个数$F(p)$,那么,题目求的就是这个$F(p)$最大的对应的人. 1 ...

  4. python 反射和内置方法

    一.isinstance和issubclass class Foo: pass class Son(Foo): pass s = Son() #判断一个对象是不是这个类的对象,传两个参数(对象,类) ...

  5. 3-----Docker实例-安装MySQL

    Docker 安装 MySQL 方法一.docker pull mysql 查找Docker Hub上的mysql镜像 runoob@runoob:/mysql$ docker search mysq ...

  6. J15W-J45W铜制截止阀厂家,J15W-J45W铜制截止阀价格 - 专题栏目 - 无极资讯网

    无极资讯网 首页 最新资讯 最新图集 最新标签   搜索 J15W-J45W铜制截止阀 无极资讯网精心为您挑选了(J15W-J45W铜制截止阀)信息,其中包含了(J15W-J45W铜制截止阀)厂家,( ...

  7. 2019.04.17 读书笔记 checked与unchecked

    在普通的编程中,我们是很容易去分析数据的大小,然后给出合理的类型,但是在很多数据库的累计中,缺存在很多隐患,特别是研发时,数据量小,求和也不会溢出,当程序运行几年后,再来一次大求和,隐形的BUG就出来 ...

  8. Pitfalls of using opencv GpuMat data in CUDA kernel code

    Please note that cv::cuda::GpuMat and cv::Mat using different memory allocation method. cv::cuda::Gp ...

  9. jQuery示例 | 分级菜单

    <!DOCTYPE html> Title .header{ background-color: black; color: wheat; } .content{ min-height: ...

  10. maven多层项目配置

    今天遇到一个maven项目有3个子项目的配置问题,一开始项目结构是混乱的,而且包引入不能正常解析. 主项目上右键,选择configure->configure and detect nested ...