mobile-touch实现时间轴特效

 使用jquery-mobile插件能够很方便的监听到移动端的滑动事件,直接复制下面代码即可:

<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap 101 Template</title>
    
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
    <style type="text/css">
      .TimeBox{
        width: 80%;
        height: 200px;
        margin: 0 auto;
        background-color: #fff; 
      }
      .TimeBox .TimeLine{
        height: 80%;
        width: 80%;
        margin: 0 auto;
        border-bottom: 1px dashed #bbb;
        position: relative;
      }
      .TimeBox .TimeLine .TimeDot{
        position: absolute;
        width: 10px;
        height: 10px;
        cursor: pointer;
        border-radius: 50%;
        background-color: #bbb;
        bottom: -5px;
        left: -5px;
        transform: scale(1,1);
        font-size: 10px;
        transition: all 0.25s;
      }
      .TimeBox .TimeLine .TimeDotAct{
        font-size: 14px;
        transform: scale(1.2,1.2);
        color: #CC3300;
        background-color: #CC3300;
      }
      .TimeBox .TimeLine .TimeDot .TimeLabel{
        position: absolute;
        top: -25px;
        margin-left: -20px;
        text-align: center;
        cursor: pointer;
      }
    </style>
  </head>
  <body>
    <div class="TimeBox">
      <div class="TimeLine">
        <div class="TimeDot TimeDotAct"><label class="TimeLabel">09:11:00</label></div>
        <div class="TimeDot"><label class="TimeLabel">09:11:00</label></div>
        <div class="TimeDot"><label class="TimeLabel">09:11:00</label></div>
        <div class="TimeDot"><label class="TimeLabel">09:11:00</label></div>
      </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
    <script type="text/javascript">
      var DotLength = $("div.TimeDot").length-1;
      $("div.TimeDot").each(function(i,val){
        var baifenbi = i*(100/DotLength);
        $(this).css("left",baifenbi+"%");
      });

      $("div.TimeDot").on("click",function(){
        console.log("click me");
        $(this).addClass("TimeDotAct");
        $(this).siblings().removeClass("TimeDotAct");
      });

      $(document).on("swipeleft",function(){
        console.log("left");
        var _this = $("div.TimeDotAct");
        _this.next().addClass("TimeDotAct");
        if(_this.next().length==0){
          return;
        }
        _this.removeClass("TimeDotAct");
      });

      $(document).on("swiperight",function(){
        console.log("right");
        var _this = $("div.TimeDotAct");
        _this.prev().addClass("TimeDotAct");
        if(_this.prev().length==0){
          return;
        }
        _this.removeClass("TimeDotAct");
      });
    </script>
  </body>
</html>

效果如下:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

专业前端小白

写了这么久文章,1分钱都没收到

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值