jQuery动画特效

jQuery中动画和特效的相关方法可以说为其添加了靓丽的一笔。开发者可以通过简单的函数实现很多特效,这在以往都是需要大量JavaScript代码开发的。本章主要通过实例,介绍jQuery中动画和特效的相关知识,包括自动显隐、渐入渐出、飞入飞出、自定义动画等。

1. 元素的显示与隐藏

- show()和hide()

2. 渐入渐出的变幻

- 再探show()和hide()

- fadeIn()和fadeOut()

3. 幻灯片效果

- slideUp()和slideDown()来模拟PPT中的类似幻灯片拉窗帘的特效

例题:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <title>元素显示和隐藏.html</title>

    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript">
    $(function(){
    $("input:first").click(function(){
     $("p").hide();//隐藏
    });

    $("input:last").click(function(){
     $("p").show();//显示 
    });
        });
    </script>

</head>

<body>
<input type="button" value="hide">
<input type="button" value="show">
<p>点击按钮查看效果</p>
<span>一段其他的文字</span>
</body>
</html>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <title>元素显示和隐藏.html</title>

    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript">
    $(function(){
    $("input:first").click(function(){
     $("p").hide(3000);//隐藏
    });

    $("input:last").click(function(){
     $("p").show(1000);//显示 
    });
        });
    </script>

</head>

<body>
<input type="button" value="hide">
<input type="button" value="show">
<p><img src="images/1.bmp" /></p>
<span>一段其他的文字</span>
</body>
</html>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <title>元素显示和隐藏.html</title>

    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript">
    $(function(){

       $("input:eq(0)").click(function(){
     $("img").fadeOut(3000);//逐渐fadeOut
    });

    $("input:eq(1)").click(function(){
     $("img").fadeIn(1000);//逐渐fadeIn 
    });
   
    $("input:eq(2)").click(function(){
     $("img").hide(3000);//逐渐隐藏
    });

    $("input:eq(3)").click(function(){
     $("img").show(1000);//逐渐显示 
    });
        });
    </script>

</head>

<body>
<input type="button" value="FadeOut">
<input type="button" value="FadeIn">
<input type="button" value="hide">
<input type="button" value="show">

<p><img src="images/1.bmp" /></p>
</body>
</html>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <title>幻灯片效果.html</title>

    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript">
   $(function(){
    $("input:eq(0)").click(function(){
     $("div").add("img").slideUp(1000);
    });

    $("input:eq(1)").click(function(){
     $("div").add("img").slideDown(1000);
    });

    $("input:eq(2)").click(function(){
     $("div").add("img").hide(1000);
    });

    $("input:eq(3)").click(function(){
     $("div").add("img").show(1000);
    });
   
   });
</script>
</head>

<body>
<input type="button" value="SlideUp">
<input type="button" value="SlideDonw">
<input type="button" value="Hide">
<input type="button" value="Show">

<div></div>
<img src="images/1.bmp">
</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值