jQuery animate动画

1.例子:选项卡

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>选项卡</title>
<script type="text/javascript" src="../jQuery库/jquery-3.3.1.min.js"></script>
<script type="text/javascript">

$(function(){
    var $btn = $(‘.btns input‘);
    var $slide = $(‘.cons .slide‘);

    /*alert($div.length),判断是否获取*/

    $btn.click(function(){
        /*移出除当前的类,siblings选择同辈元素*/
        $(this).addClass(‘current‘).siblings().removeClass(‘current‘);
        /*index()显示索引*/
        /*$div.eq($(this).index()).addClass(‘div1‘).siblings().removeClass(‘div1‘);*/

        /*stop()防止重复点击,animate()动画效果*/
        $slide.stop().animate({‘left‘:-500*$(this).index()});
    })
})
</script>

<style type="text/css">

.btns input{
    width: 100px;
    height: 40px;
    background-color: antiquewhite;
    border: 0;/*给宽高会有边框*/
}
.btns .current{
    background-color: aqua;
}
.cons{
    width: 500px;
    height: 200px;
    overflow: hidden;
    position: relative;
}
.slide{
    width: 1500px;
    height: 200px;
    position: absolute;
    left: 0;
    top: 0;
}
.cons .slide div{
    width: 500px;
    height: 200px;
    background-color: aquamarine;
    line-height: 200px;
    text-align: center;
    font-size: 30px;
    float: left;
}

/*.cons .div1{
    display: block;
}*/
</style>

</head>

<body>

<div class="btns">
    <input type="button" name="" value="01" class="current">
    <input type="button" name="" value="02">
    <input type="button" name="" value="03">
</div>

<div class="cons">
    <div class="slide">
        <div>选项卡1</div>
        <div>选项卡2</div>
        <div>选项卡3</div>
    </div>
</div>

</body>
</html>

2.animate动画

可以设置元素某属性值上的动画,可以设置一个或多个属性值,动画执行完成后会执行一个函数

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>动画</title>
<script type="text/javascript" src="../jQuery库/jquery-3.3.1.min.js"></script>
<script type="text/javascript">

$(function(){
    $(‘#btn‘).click(function(){
        /*分步执行,延时1000ms*/
        $(‘.box‘).animate({‘width‘:100},1000,function(){
            $(‘.box‘).animate({‘height‘:100},1000,function(){
                $(‘.box‘).animate({‘opacity‘:0.4});
            });
        });
    })

    $(‘#btn01‘).click(function(){
        /*每次点击加一百*/
        $(‘.box01‘).stop().animate({‘width‘:‘+=100‘})
    })
})
</script>

<style type="text/css">

.box,.box01{
    width: 300px;
    height: 300px;
    background-color: antiquewhite;
}
</style>

</head>

<body>

<input type="button" value="动画" id="btn">
<div class="box"></div>
<br>
<br>
<input type="button" value="动画" id="btn01">
<div class="box01"></div>

</body>
</html>

原文地址:http://blog.51cto.com/13742773/2339950

时间: 2024-08-27 03:57:48

jQuery animate动画的相关文章

jQuery animate()动画效果

1.jQuery动画效果 jQuery animate()方法用于创建自定义动画 $(selector).animate({params},speed,callback); //必需的 params 参数定义形成动画的 CSS 属性: //可选的 speed 参数规定效果的时长,它可以取以下值:"slow"."fast" 或毫秒: //可选的 callback 参数是动画完成后所执行的函数名称: 下面为几个实例: $("button").clic

JQuery animate 动画研究汇总

jquery.color.js要放在juqery-1.8.3.js这个核心库的下面: .aspx代码如下: <%@ Page Title="" Language="C#" MasterPageFile="~/SAMPLE_CODE/AMST_SAMPLE.master" AutoEventWireup="true" CodeFile="S1_JqueryAnimate_simple.aspx.cs"

jQuery之动画效果show()......animate()

jQuery之动画效果 1.show()显示效果 语法:show(speed,callback) Number/String,Function speend为动画执行时间,单位为毫秒.也可以为slow","normal","fast" callback可选,为当动画完成时执行的函数.   show(speed,[easing],callback) Number/String easing默认是swing,可选linear; $("#div1&qu

jQuery中动画animate(下)

jQuery中动画animate(下) animate在执行动画中,如果需要观察动画的一些执行情况,或者在动画进行中的某一时刻进行一些其他处理,我们可以通过animate提供的第二种设置语法,传递一个对象参数,可以拿到动画执行状态一些通知 .animate( properties, options ) options参数 duration - 设置动画执行的时间 easing - 规定要使用的 easing 函数,过渡使用哪种缓动函数 step:规定每个动画的每一步完成之后要执行的函数 prog

jQuery中动画animate(上)

jQuery中动画animate(上) 有些复杂的动画通过之前学到的几个动画函数是不能够实现,这时候就需要强大的animate方法了 操作一个元素执行3秒的淡入动画,对比一下2组动画设置的区别 $(elem).fadeOut(3000) $(elem).animate({ opacity:0 },3000) 显而易见,animate方法更加灵活了,可以精确的控制样式属性从而执行动画 语法: .animate( properties ,[ duration ], [ easing ], [ com

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

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

jQuery如何停止元素的animate动画,还有怎样判断是否处于动画状态?【转】

停止元素的动画方法:stop() 语法结构:stop([clearQueue],[gotoEnd]) clearQueue 和 gotoEnd 都为可选参数,为布尔值. clearQueue : 是否要清空未执行玩的动画列表 gotoEnd : 是否直接将正在执行的动画跳转到末状态 经常在hover时间的动画效果里用到 stop() 方法,可以避免动画效果与光标动作不一致时导致的延迟动画. 例如: $(".test").hover(function(){     $(this).sto

基于animate.css的jQuery文字动画插件

Morphext是一款简单.高性能和跨浏览器的jQuery文字动画插件.该文字动画jQuery插件基于Animate.css.你可以设置使用多个不同的句子,Morphext会以你指定的CSS3动画方式轮流显示它们. Morphext所做的事情是隐藏前一个文本短句,然后使用下一个来替换它.插件中已经为跨浏览器处理好了所有浏览器厂商的前缀问题,它可以为我们提供非常酷的文字动画效果. Animate.css依赖于CSS3 animations和transformations.如果浏览器不支持css3,

jQuery中animate动画第二次点击事件没反应

jQuery中animate动画第二次点击事件没反应 用animate做点击翻页动画时发现第二次点击事件动画没反应,而第一次点击有动画效果,代码如下: 复制代码 代码如下: $(".page").stop().animate({top:“-300px”}, 800, 'easeInOutExpo'); 第二次点击事件动画没反应的原因:top是page元素顶部相与其父元素顶部的距离,第一次点击后,page元素顶部已经移动到距其父元素顶部 -300px的位置,第二次点击时的并不是page在