你的位置:首页 > 软件开发 > Java > animate 实现滑动切换效果

animate 实现滑动切换效果

发布时间:2016-05-05 12:00:05
今天和大家分享一下用 animate 实现滑动切换效果的小例子 ------- 来自<一只有梦想的前端小白> 大家都知道jQuery 提供的有一下几种方法能够实现滑动效果:slideDown()slideUp()slideToggle()但是以上的滑动不太 ...

animate 实现滑动切换效果

今天和大家分享一下用 animate 实现滑动切换效果的小例子 ------- 来自<一只有梦想的前端小白>


 

大家都知道jQuery 提供的有一下几种方法能够实现滑动效果:

  1. slideDown()
  2. slideUp()
  3. slideToggle()

但是以上的滑动不太方便控制其滑动的方向,所以我们还是自己动手写一个吧。。。

其代码如下:

<!DOCTYPE html><html>  <head>    <meta charset="utf-8">    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">    <title>Examples</title>    <meta name="description" content="">    <meta name="keywords" content="">    <style type="text/css">      body{        width: 100%;        height: auto;      }      .content{        width: 150px;        height: 50px;        position: absolute;        top: 20px;        left: 20px;        overflow: hidden;        background-color: red;      }      .slide-box{        width: 300px;        position: relative;      }      .slide1{        width: 150px;        height: 50px;        float: left;        display: inline-block;        line-height: 50px;        text-align: center;        background-color: #BDD8CF;      }      .slide2{        width: 150px;        height: 50px;        float: right;        display: inline-block;        line-height: 50px;        text-align: center;        background-color: #C1C4C4;      }    </style>  </head>  <body>    <div class="content">      <div class="slide-box clearfix">      <span class="slide1">左边的元素</span>      <span class="slide2">右边的元素</span>    </div>    </div>          <script src='/images/loading.gif' data-original="js/jquery-1.11.2.min.js" type="text/javascript" charset="utf-8"></script>  <script type="text/javascript">    $(function(){      $(".content").hover(function(){        $(".slide-box").stop(true).animate({right:"150px"},'slow');      },function(){        $(".slide-box").stop(true).animate({right:"0"},'slow');      });    })  </script>  </body></html>

 

海外公司注册、海外银行开户、跨境平台代入驻、VAT、EPR等知识和在线办理:https://www.xlkjsw.com

原标题:animate 实现滑动切换效果

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录