html页面左右滑动菜单效果的实现

<!DOCTYPE html>
<html>
<head>
  <style>
    body {
      background-color: yellow; 
      padding: 0;
      margin: 0;
    }
    .container {
		padding:20px;
    }
    .left-menu {
      background-color: yellowgreen; 
      width: 0px; 
      position: absolute; 
      top: 0; 
      left: 0; 
      bottom: 0;
      transition: width .2s ease;
      overflow: auto;
      z-index: 1;
    }
    .content {
      position: absolute; 
      top: 0;
      bottom:0; 
      left:0; 
      right: 0;
      overflow: auto;
      /* z-index: 2; */
    }
  </style>
  <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>

</head>
<body>
  Edit in JSFiddle Result JavaScript HTML CSS
<div class="container">
    <div class="left-menu">
      <p>做菜单内容</p>
      <p>做菜单内容</p>
      <p>做菜单内容</p>
      <p>做菜单内容</p>
      <p>做菜单内容</p>
      <p>做菜单内容</p>
      <p>做菜单内容</p>
      <p>做菜单内容</p>
      <p>做菜单内容</p>
      <p>做菜单内容</p>
      <p>做菜单内容</p>
      <p>做菜单内容</p>
      <p>做菜单内容</p>
      <p>做菜单内容</p>
      <p>做菜单内容</p>
      <p>做菜单内容</p>
      <p>做菜单内容</p>
      <p>做菜单内容</p>
      <p>做菜单内容</p>
      <p>做菜单内容</p>
    </div>
    <div class="content">
      <div style="margin-left: 20px;margin-top: 20px;">
        <p>正文12=========</p>
        <p>正文12=========</p>
        <p>正文12=========</p>
        <p>正文12=========</p>
        <p>正文12=========</p>
        <p>正文12=========</p>
        <p>正文12=========</p>
        <p>正文12=========</p>
        <p>正文内容===================</p>
        <p>正文内容===================</p>
        <p>正文内容===================</p>
        <p>正文内容===================</p>
        <p>正文内容===================</p>
        <p>正文内容===================</p>
        <p>正文内容===================</p>
        <p>正文内容===================</p>
        <p>正文内容===================</p>
        <p>正文内容===================</p>
        <p>正文内容===================</p>
        <p>正文内容===================</p>
        <p>正文内容===================</p>
        <p>正文内容===================</p>
        <p>正文内容===================</p>
      </div>
    </div>
  </div>
 
  <script>
    $(".content").on("click", function(e) {
	  if($(".left-menu").width() == 200) {
		$(".left-menu").width(0);
	  } else {
		$(".left-menu").width(200);
	  }
	});
  </script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
  <style>
    body {
      background-color: yellow; 
      padding: 0;
      margin: 0;
    }
    .container {

    }
    .left-menu {
      background-color: yellowgreen; 
      width: 200px; 
      position: absolute; 
      top: 0; 
      left: 0; 
      bottom: 0;
      right: auto;
      transition: width .2s ease;
      overflow: auto;
      z-index: 1;
    }
    .content {
      position: absolute; 
      top: 0;
      bottom:0; 
      left:0; 
      right: 0;
      overflow: auto;
      z-index: 2;
      transform: translate3d(0, 0, 0);
      width: auto;
      height: auto;
      background-color: yellow;
    }
  </style>
  <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>

</head>
<body>
  Edit in JSFiddle Result JavaScript HTML CSS
 <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery.transit/0.9.12/jquery.transit.js'></script>
<div class="container">
    <div class="left-menu">
      <p>做菜单内容</p>
      <p>做菜单内容</p>
      <p>做菜单内容</p>
      <p>做菜单内容</p>
      <p>做菜单内容</p>
      <p>做菜单内容</p>
      <p>做菜单内容</p>
      <p>做菜单内容</p>
      <p>做菜单内容</p>
      <p>做菜单内容</p>
      <p>做菜单内容</p>
      <p>做菜单内容</p>
      <p>做菜单内容</p>
      <p>做菜单内容</p>
      <p>做菜单内容</p>
      <p>做菜单内容</p>
      <p>做菜单内容</p>
      <p>做菜单内容</p>
      <p>做菜单内容</p>
      <p>做菜单内容</p>
    </div>
    <div class="content">
      <div style="margin-top: 200px;">
        <p>正文内容===================</p>
        <p>正文内容===================</p>
        <p>正文内容===================</p>
        <p>正文内容===================</p>
        <p>正文内容===================</p>
        <p>正文内容===================</p>
        <p>正文内容===================</p>
        <p>正文内容===================</p>
        <p>正文内容===================</p>
        <p>正文内容===================</p>
        <p>正文内容===================</p>
        <p>正文内容===================</p>
        <p>正文内容===================</p>
        <p>正文内容===================</p>
        <p>正文内容===================</p>
      </div>
    </div>
  </div>
 
  <script>
    $(".content").on("click", function(e) {
  
  if($(".content").css("transform") == "matrix(1, 0, 0, 1, 0, 0)") {
    $(".content").transition({ 
      transform: 'translateX(200px)' 
    });  
  } else {
    $(".content").transition({ 
      transform: 'translateX(0px)' 
    });
  }

});
  </script>
</body>
</html>

https://fangjian0423.github.io/2015/10/29/html-left-right-menu/ 

感谢原作者

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
实现类似美团菜单滑动效果左右联动,可以使用一些现成的 JavaScript 插件或者自己编写 JavaScript 代码实现。 其中,比较常用的插件是 Swiper 和 Slick。这两个插件都支持左右联动,可以根据具体需求进行配置和使用。 如果你想自己编写 JavaScript 代码实现左右联动,可以通过监听滚动事件来实现。首先需要获取到左右两个滚动容器的 DOM 元素,并且监听它们的滚动事件。当其中一个滚动容器滚动时,计算它的滚动位置,然后将另一个滚动容器滚动到对应的位置即可。 具体实现方式可以参考以下示例代码: ```html <div class="container"> <div class="left-scroll"> <!-- 左侧滚动容器的内容 --> </div> <div class="right-scroll"> <!-- 右侧滚动容器的内容 --> </div> </div> <script> const container = document.querySelector('.container'); const leftScroll = document.querySelector('.left-scroll'); const rightScroll = document.querySelector('.right-scroll'); leftScroll.addEventListener('scroll', () => { const scrollLeft = leftScroll.scrollLeft; rightScroll.scrollTo(scrollLeft, 0); }); rightScroll.addEventListener('scroll', () => { const scrollLeft = rightScroll.scrollLeft; leftScroll.scrollTo(scrollLeft, 0); }); </script> ``` 以上代码中,通过监听左侧和右侧滚动容器的滚动事件,实现左右联动的效果。当左侧滚动容器滚动时,右侧滚动容器也会滚动到对应的位置;当右侧滚动容器滚动时,左侧滚动容器也会滚动到对应的位置。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值