jQuery vue仿美团订餐系统分类菜单切换代码

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>点餐</title>
    <link rel="stylesheet" type="text/css" href="css/style.css">
  <head>
<body>
  <div class="header"></div>
  <div class="swiper-container">
    <ul class="swiper-container-ul">
      <li class="swiper-container-ul-li actives">商品</li>
      <li class="swiper-container-ul-li">店铺</li>
    </ul>
    <div class="swiper-wrapper">
      <div class="swiper-slide">
        <div class="content">
          <div class="left" id="left">
            <ul>
              <li v-for="item in items">{{item.name}}</li>
            </ul>
          </div>
          <div class="right" id="right">
            <ul>
              <li v-for="item in items">
                <div class="class-title">{{item.class}}</div>
                <div v-for="ite in item.list">
                  <div class="item">
                    <div class="item-left">
                      <div class="item-img"></div>
                    </div>
                    <div class="item-right">
                      <div class="title">{{ite.title}}</div>
                      <div class="subtitle"></div>
                      <div class="price"></div>
                    </div>
                  </div>
                </div>
              </li>
            </ul>
          </div>
        </div>
      </div>
      <div class="swiper-slide" style="display:none;">
        店铺介绍
      </div>
    </div>
  </div>
  <script src="js/jquery.min.js"></script>
  <script src="js/vue.min.js"></script>
  <script type="text/javascript">
  $(function(){
    $('.content').css('height',$('.right').height());
    $('.left ul li').eq(0).addClass('active');
    $(window).scroll(function(){
      if($(window).scrollTop() >= 150){
        $('.swiper-container-ul').css('position','fixed');
        $('.left').css('position','fixed');
        $('.right').css('margin-left',$('.left').width());
      }else {
        $('.swiper-container-ul').css('position','');
        $('.left').css('position','');
        $('.right').css('margin-left','');
      };
      //滚动到标杆位置,左侧导航加active
      $('.right ul li').each(function(){
        var target = parseInt($(this).offset().top-$(window).scrollTop()-150);
        var i = $(this).index();
        if (target<=0) {
          $('.left ul li').removeClass('active');
          $('.left ul li').eq(i).addClass('active');
        }
      });
    });
    $('.left ul li').click(function(){
      var i = $(this).index('.left ul li');
      $('body, html').animate({scrollTop:$('.right ul li').eq(i).offset().top-40},500);
    });
    $('.swiper-container-ul-li').click(function(){
      var index = $(this).index();
      if(index == 0){
        $('.swiper-slide').eq(0).show();
        $('.swiper-container-ul-li').eq(0).addClass('actives');
        $('.swiper-slide').eq(1).hide();
        $('.swiper-container-ul-li').eq(1).removeClass('actives');
      }else {
        $('.swiper-slide').eq(0).hide();
        $('.swiper-container-ul-li').eq(0).removeClass('actives');
        $('.swiper-slide').eq(1).show();
        $('.swiper-container-ul-li').eq(1).addClass('actives');
      }
    });
  });
  </script>
  <script>
  var left = new Vue({
    el: '#left',
    data: {
      items: [
        { name : '分类1' },
        { name : '分类2' },
        { name : '分类3' },
        { name : '分类4' },
        { name : '分类5' },
        { name : '分类6' },
        { name : '分类7' },
        { name : '分类8' }
      ]
    }
  });
  var right = new Vue({
    el: '#right',
    data: {
      items: [
        { class : '分类1',list : [ { title : '1' },{ title : '2' } ] },
        { class : '分类2',list : [ { title : '1' },{ title : '2' } ] },
        { class : '分类3',list : [ { title : '1' },{ title : '2' } ] },
        { class : '分类4',list : [ { title : '1' },{ title : '2' } ] },
        { class : '分类5',list : [ { title : '1' },{ title : '2' } ] },
        { class : '分类6',list : [ { title : '1' },{ title : '2' } ] },
        { class : '分类7',list : [ { title : '1' },{ title : '2' } ] },
        { class : '分类8',list : [ { title : '1' },{ title : '2' } ] }
      ]
    }
  });
  </script>
</body>
</html>

css:
*{
  padding: 0;
  margin: 0;
}
.header{
  width: 100%;
  height: 150px;
  background: #555;
}
.swiper-container-ul{
  list-style: none;
  overflow: hidden;
  width: 100%;
  background: #fff;
  top: 0;
}
.swiper-container-ul-li{
  width: 50%;
  height: 40px;
  line-height: 40px;
  float: left;
  text-align: center;
}
.actives{
  border-bottom: 1px solid #3190e8;
  color: #3190e8;
}
.content{
  width: 100%;
  overflow: hidden;
}
.left{
  top: 41px;
  float: left;
  width: 25%;
  height: 100%;
  background: #eee;
}
.left ul{
  list-style: none;
}
.left ul li{
  padding: 15px 5px;
  text-align: center;
}
.active{
  background: #fff;
  border-left: 2px solid #3190e8;
}
.right{
  float: left;
  width: 75%;
  height: 100%;
}
.right ul{
  list-style: none;
}
.class-title{
  padding: 7px 10px;
  background: #eee;
}
.item{
  overflow: hidden;
  width: 100%;
  padding: 10px;
  background: #fff;
  border-bottom: 1px solid #eee;
}
.item-left{
  float: left;
}
.item-right{
  float: left;
  padding: 0 10px;
}
.item-img{
  width: 100px;
  height: 100px;
  background: #eee;
}
.title{
  width: 100px;
  height: 20px;
  margin-top: 10px;
  background: #eee;
}
.subtitle{
  width: 70px;
  height: 20px;
  margin-top: 10px;
  background: #eee;
}
.price{
  width: 50px;
  height: 20px;
  margin-top: 10px;
  background: #eee;
}


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
【为什么前端都要学习Vue】 这几年Vue.js成为前端框架中最火的一个。越来越多的网站前端开始采用Vue.js开发。是开源世界华人的骄傲,作者是我国的尤雨溪大神。相对于其他前端框架,Vue 更容易上手!正因为它简单易学,很多前端开发工程师可以很快掌握并且应用到实际开发中。如果说你想用最短的时间来学习一个框架,快速上手项目,Vue是不二之选。 【学员收益】 1)大部分学员想要学习Vue,但是无奈缺少一个好老师,董老师将手把手带领你学习,让你彻底掌握Vue框架。 2)课程将会长期维护,内容更超值,本课程基于最新的版本进行讲解,并且老师会更新升级到3.0稳定版本。 3)学完该课程后不仅能学到Vue的设计和开发技能,还能培养市场思维、用户思维、设计思维,并能够利用掌握的技术开发Vue项目,获取额外的收益。 【课程收获】 1、从基础知识到项目实战,内容涵盖Vue各个层面的知识和技巧2、学习曲线平缓,前端新人也可以看得懂3、贴近企业项目,按照企业级代码标准和工程开发的流程进行讲解4、让你能够独立开发高颜值的项目 5、项目涉及14大功能组件,从基础组件到业务组件,一站式全掌握 【项目效果】 本课程打造的是高颜值的美团外卖项目。不仅界面美观,而且涉及到了众多页面。多说无益,请大家扫码查看课程效果。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值