知识点---animate()动画滞后执行的解决方案
jQuery动画:
animate 容易出现连续触发、滞后反复执行的现象;
针对 jQuery 中 slideUp、slideDown、animate 等动画运用时出现的滞后反复执行等问题的解决方法有如下:
1、在触发元素上的事件设置为延迟处理, 即可避免滞后反复执行的问题(使用setTimeout)
2、在触发元素的事件时预先停止所有的动画,再执行相应的动画事件(使用stop)推荐这种。
//第二种方式 $(".container").stop();//停止当前动画,继续下一个动画 $(".container").stop(true);//清除元素的所有动画 $(".container").stop(false, true);//让当前动画直接到达末状态 ,继续下一个动画 $(".container").stop(true, true);//清除元素的所有动画,让当前动画直接到达末状态
//例如,
1 $(".container").stop().animate({
2 marginTop:"60px",
3 width:"100px",
4 height:"50px"
5 },500);
动画效果一、
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("#start").click(function(){
$("div").animate({height:300},1500);
$("div").animate({width:300},1500);
$("div").animate({height:100},1500);
$("div").animate({width:100},1500);
});
$("#stop").click(function(){
$("div").clearQueue();
});
});
</script>
</head>
<body>
<button id="start">开始动画</button>
<button id="stop">停止动画</button>
<br><br>
<div style="background:red;height:100px;width:100px;"></div>
</body>
</html>
动画效果二、
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("#flip").click(function(){
$("#panel").slideToggle("slow");
});
});
</script>
<style type="text/css">
#panel,#flip
{
padding:5px;
text-align:center;
background-color:#e5eecc;
border:solid 1px #c3c3c3;
}
#panel
{
padding:50px;
display:none;
}
</style>
</head>
<body>
<div id="flip">点我,显示或隐藏面板。</div>
<div id="panel">Hello world!</div>
</body>
</html>
动画效果三、
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$(".btn1").click(function(){
$("p").animate({top:"100px"});
});
$(".btn2").click(function(){
$("p").animate({top:"0px"});
});
});
</script>
</head>
<body>
<button class="btn1">动画</button>
<button class="btn2">重置</button>
<p style="position:relative">这是一个段落。</p>
</body>
</html>
知识点---animate()动画滞后执行的解决方案的更多相关文章
- animate 动画滞后执行的解决方案
jQuery动画: animate 容易出现连续触发.滞后反复执行的现象: 针对 jQuery 中 slideUp.slideDown.animate 等动画运用时出现的滞后反复执行等问题的解决方法有 ...
- jquery animate 动画效果使用解析
animate的意思是:使有生气:驱动:使栩栩如生地动作:赋予…以生命作为形容词:有生命的:活的:有生气的:生气勃勃的 先看动画效果:http://keleyi.com/keleyi/phtml/jq ...
- jQuery 动画的执行
jQuery 动画的执行 <%@ page language="java" import="java.util.*" pageEncoding=" ...
- CSS3新特性—animate动画
1.animate介绍 1. @keyframes 自定义动画名称 { from { } to { } } 2. 通过动画名称调用动画集 animation-name: 动画集名称. 3. 属性介绍: ...
- 解决animate动画连续播放bug
在animate动画中,如果几个div之间频繁切换,会导致鼠标移开后,动画仍在继续,解决方法有两个 一个,判断当前是否在运行动画: if(!$(".block").is(" ...
- jQuery中animate动画第二次点击事件没反应
jQuery中animate动画第二次点击事件没反应 用animate做点击翻页动画时发现第二次点击事件动画没反应,而第一次点击有动画效果,代码如下: 复制代码 代码如下: $(".page ...
- jquery IE6 下animate 动画的opacity无效
jquery IE6 下animate 动画的opacity无效,其实是有效的,因为IETester的一个小BUG 原生IE6 没问题...呵呵~~
- UIIimageView读取图片的两种方式及动画的执行
/**count:图片数量 name:图片名称*/ - (void)runAnimationWithCount:(int)count name:(NSString *)name { if(self.t ...
- Android 中加载几百张图片做帧动画防止 OOM 的解决方案
Android 中加载几百张图片做帧动画防止 OOM 的解决方案 最近,项目中有个需求:就是要做一个帧动画,按理说这个是很简单的!但是我能说这个帧动画拥有几百张图片吗?...... 填坑一 ---帧动 ...
随机推荐
- 筛选最小值---verilog
筛选最小值---verilog `timescale 1ns / 1ps /////////////////////////////////////////////////////////////// ...
- c++ map 注意事项
1. 往map里面插入元素: 下标方式[]: map[key] = value; 调用insert: map.insert(make_pair(key, value)); 下标方式 ...
- 通俗易懂理解Linux文件权限修改chmod命令
chmod g+w filename 给同组用户增加filename文件的写权限 chmod go+rw filename 给同组和组外用户增加写和读的权限 chmod g-w filename 给同 ...
- sc.exe用法详解
sc.exe是帮助开发 WindowsNT 服务的工具,这里我来说说如何使用好sc.exe. 我们打开命令提示符(以管理员身份运行): 输入sc delete ServiceName(服务名) 即可 ...
- gmer ver2.1.19357
gmer是一款来自 波兰 的多功能安全监控分析程序.它可以结束除了System和System Idle Process以外几乎所有的进程,还可以查看被隐藏的进程,服务以及驱动(以红色的方式显示此进程. ...
- hive动态分区问题--分区为中文
报错如下: Loading data to table data_da.tmp_wlw_test partition (stat_date=2017-05-11, business_type_name ...
- extentreports
关于extentreports使用的一些个人见解 首先导入jar包, 使用maven导入,我再次首先导入的是 <version>4.0.5</version>版本的jar包,但 ...
- Specify 的含义 ------ 转载
specify block用来描述从源点(source:input/inout port)到终点(destination:output/inout port)的路径延时(path delay),由sp ...
- vue3.0中如何使用ueditor
1.在官网下载一个ueditor版本[https://ueditor.baidu.com/website/download.html],解压后放到public文件下的static文件中重命名为Edit ...
- [Vue warn]: Duplicate keys detected: '1'. This may cause an update error
今天遇到这个问题,遇到这个问题多数因为:key值的问题 第一种情况(key重复) <div class="name-list" v-for="(item,index ...