浅入jquery-各种简单的效果[three]

简介: 前言在现在的网页建设中效果是非常常用的。 比如说当你鼠标移动到某个地方的时候出现的提示。 当你鼠标点击的时候一些切换的效果。 我相信每个人都不能没有注意这些特效。 因为有了这些效果才能使我们的网页更加的美观,功能更加的丰富。 掌握效果的使用也是非常基础而且有必要的基础课程。效果种类1.显示和隐藏。2.淡入淡出3.移动4.动画显示和隐藏

前言

在现在的网页建设中效果是非常常用的。
比如说当你鼠标移动到某个地方的时候出现的提示。
当你鼠标点击的时候一些切换的效果。
我相信每个人都不能没有注意这些特效。
因为有了这些效果才能使我们的网页更加的美观,功能更加的丰富。
掌握效果的使用也是非常基础而且有必要的基础课程。

效果种类

1.显示和隐藏。

2.淡入淡出

3.移动

4.动画

显示和隐藏。

简单介绍

显示和隐藏是最基本的效果了。
而且是随处可见的。例如csdn的首页的这里写图片描述

很典型的一个例子。

简单示例

仿照网易邮箱记住密码做的。
主要使用hide和show方法
和html中设置style可见度是一个道理。

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
    <script src="js/jquery-1.11.0.min.js"></script>
    <script>
        $(document).ready(function () {
            $("div").mouseenter(function () {
                $("#info").show();
            })
            $("div").mouseleave(function () {
                $("#info").hide();
            })
        })
    </script>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <div align="center">
        <input type="checkbox" value="一周内免登陆"/><span>一周内免登陆</span>
    </div>
    <p id="info" align="center" style="display: none">xxxxxxxxxxxxxxxxxx</p>
</body>
</html>

浅入浅出

简单介绍

也算是一种显示和隐藏功能,但是可以设置显示和隐藏的速度和透明度。

方法介绍

  1. fadeIn(speed,callback) 可以设置淡入的时间以及callback函数。
  2. fadeOut(speed,callback)可以设置淡出时间和callback函数。
  3. fadeToggle(speed,callback)是上述两个函数的结合体。可以在两种状态之间切换
  4. fadeTo(speed,opacity,callback) 可以设置时间透明度callback函数。

简单示例

和上述的例子基本相同。
只要替换函数名即可。

1.fadeIn和fadeOut

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
    <script src="js/jquery-1.11.0.min.js"></script>
    <script>
        $(document).ready(function () {
            $("div").mouseenter(function () {
                $("#info").fadeIn(1000);
            })
            $("div").mouseleave(function () {
                $("#info").fadeOut(1000);
            })
        })
    </script>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <div align="center">
        <input type="checkbox" value="一周内免登陆"/><span>一周内免登陆</span>
    </div>
    <p id="info" align="center" style="display: none">xxxxxxxxxxxxxxxxxx</p>
</body>
</html>

2.fadeToggle

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
    <style>
        .div {
    width: 100px;
  height: auto;
    margin-right: auto;
    margin-left: auto;
}
       .div .div-top {
    height: 100px;
    background-color: #049f3a;
}

.div .div-bottom {
    background-color: aqua;
    height: 200px;
}
    </style>
    <script src="js/jquery-1.11.0.min.js"></script>
    <script>
         $(document).ready(function () {
            $(".div-top").click(function () {
                $(".div-bottom").toggle(1000);
            });
        });
    </script>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <div class="div" align="center">
        <div class="div-top">点击我测试</div>
        <div class="div-bottom"></div>

    </div>
</body>
</html>

3.dadeto

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
    <style>
        .div {
    width: 100px;
  height: auto;
    margin-right: auto;
    margin-left: auto;
}
       .div .div-top {
    height: 100px;
    background-color: #049f3a;
}

.div .div-bottom {
    background-color: aqua;
    height: 200px;
}
    </style>
    <script src="js/jquery-1.11.0.min.js"></script>
    <script>
         $(document).ready(function () {
            $(".div-top").click(function () {
                $(".div-bottom").fadeTo(1000,0.5);
            });
        });
    </script>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <div class="div" align="center">
        <div class="div-top">点击我测试</div>
        <div class="div-bottom"></div>

    </div>
</body>
</html>

移动效果

简单介绍

通过移动效果其实和消失移动的功能和和相似。

方法介绍

  1. slideDown() //向下滑动
  2. slideUp() //向上滑动
  3. slideToggle() //向上下滑动的循环

简单示例

<!DOCTYPE html>
<html>
<head>
<script src="/jquery/jquery-1.11.1.min.js"></script>
<script type="text/javascript"> 
$(document).ready(function(){
  $(".flip").click(function(){
    $(".panel").slideDown("slow");
    //$(".panel").slideUp("slow");
    //$(".panel").slideToggle("slow");
  });
});
</script>

<style type="text/css"> 
div.panel,p.flip
{
margin:0px;
padding:5px;
text-align:center;
background:#e5eecc;
border:solid 1px #c3c3c3;
}
div.panel
{
height:120px;
display:none;
}
</style>
</head>

<body>

<div class="panel">
<p>仔细观察</p>
<p>移动过程</p>
</div>

<p class="flip">请点击这里</p>

</body>
</html>

动画

简单介绍

在原来的效果之上加上对属性的一些操作使得如同动画一般。

主要方法

animate({params},speed,callback) //属性集合,速度和回调函数

简单示例

<!DOCTYPE html>
<html>
<head>
<script src="/jquery/jquery-1.11.1.min.js"></script>
<script> 
$(document).ready(function(){
  $("button").click(function(){
    var div=$("div");
    div.animate({height:'300px',opacity:'0.4'},"slow");
    div.animate({width:'300px',opacity:'0.8'},"slow");
    div.animate({height:'100px',opacity:'0.4'},"slow");
    div.animate({width:'100px',opacity:'0.8'},"slow");
  });
});
</script> 
</head>

<body>

<button>开始动画</button>
<div style="background:#98bf21;height:100px;width:100px;position:absolute;">
</div>

</body>
</html>

总结

很多效果都需要自己去操作,试着模仿网站中的一些效果。
我相信主要尝试肯定可以成功。

目录
相关文章
|
JavaScript 前端开发
jQuery实现手风琴效果
我们在项目总经常会遇到制作手风琴效果的需求。其实实现手风琴效果不难,特别是使用jQuery来实现,就更加简单了。这里给大家分享两个手风琴效果的制作方法。
1261 0
|
JavaScript 前端开发 Go
|
Web App开发 JavaScript 前端开发
推荐30个新鲜出炉的精美 jQuery 效果
  jQuery 是最流行和使用最广泛的 JavaScript 框架,它简化了HTML文档遍历,事件处理,动画以及Ajax交互,帮助Web开发人员更快速的实现各种精美的界面效果。jQuery 的易扩展性吸引了来自全球的开发者来共同编写 jQuery 插件,这些优秀的 jQuery 插件不仅能够增强网站的可用性,有效的改善用户体验,还可以加快开发速度,节省开发时间。
993 0
|
6月前
|
JavaScript
Jquery插件知识之Jquery.cookie实现页面传值
Jquery插件知识之Jquery.cookie实现页面传值
36 0
|
7月前
|
JavaScript
jQuery 插件自用列表
jQuery 插件自用列表
29 0
|
3月前
|
JavaScript
jQuery图片延迟加载插件jQuery.lazyload
jQuery图片延迟加载插件jQuery.lazyload
|
3月前
|
JavaScript 数据可视化 前端开发
jQuery-JS插件-第9次课-使用插件让领导对你刮目相看-附案例作业
jQuery-JS插件-第9次课-使用插件让领导对你刮目相看-附案例作业
19 0