关于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" ...
随机推荐
- js实现小球碰撞游戏
效果图: 效果图消失只是截的gif图的问题 源码: <!DOCTYPE html> <html lang="en"> <head> <m ...
- java设计模式:简单实现生产者和消费者模式
*博客搬家:初版发布于 2016/04/15 20:31 原博客地址:https://my.oschina.net/sunqinwen/blog/660881 本实例中单独为生产者和消费者各开辟 ...
- Go语言字符串
Go语言的字符串是一个用UTF-8编码的变宽字符序列,它的每一个字符都用一个或多个字节表示 . 在Go语言中,没有字符类型,字符类型是rune类型,rune是int32的别称.可使用 []byte() ...
- 2.7 Go channel
channel简单示例 package main import ( "fmt" "time" ) //channel的创建,发送,接收 func channe1 ...
- 转 crs damon can't start 2个例子
###sample 1 "node 1 (10.198.127.5): ps -ef|grep ora.crsd root 45613166 47185944 0 10:24:35 pts/ ...
- KafKa 启动
Zookeeper 运行kafka需要使用Zookeeper,所以要先启动Zookeeper,如果没有Zookeeper,可以使用kafka自带打包和配置好的Zookeeper 1.进入kafka的b ...
- mysql 02
CREATE TABLE emp(eid INT,ename VARCHAR(20),egender CHAR(2),ebirthday DATE,eemail CHAR(10),eramark VA ...
- Comparing deep learning frameworks: Tensorflow, CNTK, MXNet, & Caffe
https://imaginghub.com/blog/10-a-comparison-of-four-deep-learning-frameworks-tensorflow-cntk-mxnet-a ...
- 更新Mac双系统多分区
前言制作Mac USB系统安装盘安装Mac OS 10.12制作win10 USB系统安装盘安装win10windows多分区实现 前言 同事有一台mac pro,系统是mac os 10.9+win ...
- Asp.net MVC中repository和service的区别
在Asp.net MVC controller的底层,常常有提到repository和service layer, 好像都是逻辑相关的层,那么它们到底是什么区别呢? 简单的说: repository就 ...