关于JQuery animate()方法
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()方法的更多相关文章
- jQuery animate方法开发极客标签Logo动画融合效果
在线演示 本地下载 jQuery的animate方法基础使用,演示如何生成一个jQuery animate方法开发极客标签Logo动画融合效果 相关代码录播:jQuery animate方法开发极客标 ...
- jquery animate()方法 语法
jquery animate()方法 语法 作用:animate() 方法执行 CSS 属性集的自定义动画.该方法通过CSS样式将元素从一个状态改变为另一个状态.CSS属性值是逐渐改变的,这样就可以创 ...
- jQuery animate() 方法
定义和用法 animate() 方法执行 CSS 属性集的自定义动画. 该方法通过 CSS 样式将元素从一个状态改变为另一个状态.CSS属性值是逐渐改变的,这样就可以创建动画效果. 只有数字值可创建动 ...
- jquery animate()方法使用的注意事项
当使用 animate() 时,必须使用 Camel 标记法书写所有的属性名,比如,必须使用 paddingLeft 而不是 padding-left,使用 marginRight 而不是 margi ...
- jQuery 效果 - 动画 animate() 方法
我们先看一个demo <!DOCTYPE html> <html> <head> <script src="/jquery/jquery-1.11. ...
- jQuery animate()动画效果
1.jQuery动画效果 jQuery animate()方法用于创建自定义动画 $(selector).animate({params},speed,callback); //必需的 params ...
- 使用jQuery的animate方法制作滑动菜单
周末看Ziv小威的博客<制作滑动条菜单,如何延时处理滑动效果,避免动画卡顿>,参见地址:http://www.cnblogs.com/zivxiaowei/p/3462964.html.是 ...
- Jquery动画方法 jquery.animate()
目前在学习Oracle数据库,由于刚接触,学校让练习练习HTML内容,就想起了老师以前提起过的animate方法 animate是jquery的一个方法,这个方法主要功能是能实现比较平滑的动态效果,所 ...
- jQuery 效果 - animate() 方法
http://www.w3school.com.cn/jquery/effect_animate.asp 实例 改变 "div" 元素的高度: $(".btn1" ...
随机推荐
- 数据库--sql文件
sql 脚本是包含一到多个 sql 命令的 sql 语句集合 使用 Linux: mysqldump 命令 1.导出数据和表结构: mysqldump -u 用户名 -p 数据库名称 > nam ...
- 搭建gogs
https://blog.csdn.net/hwm_life/article/details/82969005 服务器环境 CentOS 7 64位 安装Gogs所需的其它环境 需要安装的依赖有Ngi ...
- java 使用idea将工程打成jar并创建成exe文件类型执行
https://blog.csdn.net/weixin_38310965/article/details/80392767
- xtts v4for oracle 11g&12c(文档ID 2471245
xtts v4for oracle 11g&12c(文档ID 2471245.1) 序号 主机 操作项目 操作内容 备注: 阶段一:初始阶段 1.1 源端 环境验证 migrate_check ...
- A problem has been detected and windows has been shut down to prevent damage
问题描述 问题解决 参考百度经验, 未解决,重装系统,U盘启动解决.过程可以参考上一篇博文.
- 后缀自动机 && 题目
因为明天要讲解后缀自动机了,所以只能抱抱佛脚,临时做做题目.其实很久以前看过,但是不太懂,看的是clj的原文,不太懂.现在只能临时看看是怎么弄的,应付下. ---------------------- ...
- oracle 中的exists 和 in 效率问题
oracle中的 exists 和 in 的效率问题 --------------------------------------------------------------- +++++++++ ...
- MySQL 的数据库、表基本操作
1.链接数据库 mysql -u root -ppassword 2创建数据库 create database mr_book; 3选择数据库 use mr_book; 4 创建表 create ta ...
- unity2018使用tileMap生成地图 类似泰拉瑞亚创建和销毁地图块
参考网站:https://blog.csdn.net/pz789as/article/details/79540890 using System.Collections; using System.C ...
- spring自定义标签之 规范定义XSD
引言: spring的配置文件中,一切的标签都是spring定义好的.<bean/>等等,有了定义的规范,才能让用户填写的正常可用.想写自定义标签,但首先需要了解XML Schema De ...