关于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" ...
随机推荐
- docker-compose部署mysql配置
docker-compose部署mysql配置文件如下 version: ' services: mysql: image: mysql environment: - MYSQL_ROOT_PASSW ...
- pip报failed to create process
使用pip命令的时候报failed to create process 1.错误提示窗口如下图 2.报这个错误的原因,是因为你改动了python的目录名称或位置.因为,我的电脑是安装了anaconda ...
- for ++i i++
study from: https://zhidao.baidu.com/question/339305815.html 处理方式的不同,速度上的微妙不同 有些高手能喜欢用++i,速度上快一点
- Vue触发input选取文件点击事件
CSS .upload-btn-box { margin-bottom: 10px; button { margin-right: 10px; } input[type=file] { display ...
- oracle--块信息深入解析
一,创建 Data Block是数据库中最小的I/O单元 01,建立一个新的表空间 查看默认表空间位置 select TABLESPACE_NAME,FILE_NAME from dba_data_f ...
- DataTable对象
DataTable表示一个内存中的关系数据表,可以独立创建和使用,也可以有其他.NET Framework对象使用,最常见的情况是作为DataSet的成员使用.DataTable对象由DataColu ...
- db2 tsm backup fails with rc–50(1)
2015-01-05-19.21.54.477532+000 E8484227A347 LEVEL: Error PID : 10027058 TID : ...
- Robot Framework自动化测试三(selenium API)
Robot Framework Selenium API 说明: 此文档只是将最常用的UI 操作列出.更多方法请查找selenium2Library 关键字库. 一.浏览器驱动 通过不同的浏览器 ...
- POI基本操作
1.读取excel文件 InputStream is = new FileInputStream(filesrc); POIFSFileSystem fs = new POIFSFileSystem( ...
- Android表格布局之设置边框
Android表格布局本身没有边框,不过可以通过背景色的设置可以实现表格边框的显示. 首先可以设置TableRow的背景色,然后设置内容的背景色.根据它们的颜色差就出现了边框.只要微调Content与 ...