后台管理系统:固定表格表头和前几列

 <script src="./angular.js"></script>
  <link rel="stylesheet" href="./bootstrap.min.css">
  <title></title>
  <style>
    .table {
      margin-bottom: 0;
    }

    .lefttd {
      z-index: 900;
      background: #fff;
    }

    .div {
      width: 500px;
      height: 500px;
      overflow: auto;
      position: relative;
      margin: 0 auto;
    }

    #left-div {
      position: absolute;
      top: 0;
      left: 0;
      z-index: 1000;
      background: gray;
    }
    #right-div {
      position: absolute;
      top: 0;
      left: 0;
    }
  </style>
</head>

<body ng-controller="bodyCtrl">

  <div class="div" id="div">
    <div id="left-div">
      <table class="table table-bordered">
        <tr>
          <td>
            <div style="width:100px">xxx</div>
          </td>
          <td>
            <div style="width:150px">yyy</div>
          </td>
        </tr>
      </table>
    </div>
    <div id="right-div">
      <table style="position:relative;" class="table table-bordered">
        <thead id="thead" style="z-index: 100;background:red;">
          <tr>
            <td>
              <div style="width:100px">xxx</div>
            </td>
            <td>
              <div style="width:150px;">yyy</div>
            </td>
            <td>123</td>
            <td>123</td>
            <td>123</td>
            <td>123</td>
            <td>123</td>
            <td>123</td>
            <td>123</td>
          </tr>
        </thead>
        <tbody>
          <tr ng-repeat="m in list" class="set-height">
            <td class="lefttd">
              {{m.name}}
            </td>
            <td class="lefttd">
              <div style="word-break:break-all;">
                {{m.age}}
              </div>
            </td>
            <td>{{m.sex}}</td>
            <td>{{m.girl}}</td>
            <td>{{m.eat}}</td>
            <td>{{m.write}}</td>
            <td>{{m.book}}</td>
            <td>{{m.class}}</td>
            <td>{{m.score}}</td>
          </tr>
        </tbody>

      </table>
    </div>
  </div>

  <script>
    var app = angular.module('myApp', ['ng'])
    // app.directive('repeatFinish', ['$timeout', function ($timeout) {
    //   return {
    //     link: function (scope, element, attr) {
    //       if (scope.$last == true) {
    //         $timeout(function () {
    //           scope.$eval(attr.repeatFinish);
    //         });
    //       }
    //     }
    //   }
    // }])
    app.controller('bodyCtrl', ['$scope', function ($scope) {
      $scope.list = []
      $scope.list = [
        {
          name: 'tom',
          age: '18485454545454545465465646',
          sex: 'man',
          score: 75,
          class: '3-4',
          girl: 'mary',
          book: 'hong',
          write: 'pencil',
          eat: 'meat'
        },
        {
          name: 'tom',
          age: '18485454545454545465465646',
          sex: 'man',
          score: 75,
          class: '3-4',
          girl: 'mary',
          book: 'hong',
          write: 'pencil',
          eat: 'meat'
        },
        {
          name: 'tom',
          age: '18485454545454545465465646',
          sex: 'man',
          score: 75,
          class: '3-4',
          girl: 'mary',
          book: 'hong',
          write: 'pencil',
          eat: 'meat'
        },
        {
          name: 'tom',
          age: '18485454545454545465465646',
          sex: 'man',
          score: 75,
          class: '3-4',
          girl: 'mary',
          book: 'hong',
          write: 'pencil',
          eat: 'meat'
        },
        {
          name: 'tom',
          age: '18485454545454545465465646',
          sex: 'man',
          score: 75,
          class: '3-4',
          girl: 'mary',
          book: 'hong',
          write: 'pencil',
          eat: 'meat'
        },
        {
          name: 'tom',
          age: '18485454545454545465ffgsddffffffffffffffffffffffffffffffffff465646',
          sex: 'man',
          score: 75,
          class: '3-4',
          girl: 'mary',
          book: 'hong',
          write: 'pencil',
          eat: 'meat'
        },
        {
          name: 'tom',
          age: 18,
          sex: 'man',
          score: 75,
          class: '3-4',
          girl: 'mary',
          book: 'hong',
          write: 'pencil',
          eat: 'meat'
        },
        {
          name: 'tom',
          age: 18,
          sex: 'man',
          score: 75,
          class: '3-4',
          girl: 'mary',
          book: 'hong',
          write: 'pencil',
          eat: 'meat'
        },
        {
          name: 'tom',
          age: 18,
          sex: 'man',
          score: 75,
          class: '3-4',
          girl: 'mary',
          book: 'hong',
          write: 'pencil',
          eat: 'meat'
        },
        {
          name: 'tom',
          age: 18,
          sex: 'man',
          score: 75,
          class: '3-4',
          girl: 'mary',
          book: 'hong',
          write: 'pencil',
          eat: 'meat'
        },
        {
          name: 'tom',
          age: 18,
          sex: 'man',
          score: 75,
          class: '3-4',
          girl: 'mary',
          book: 'hong',
          write: 'pencil',
          eat: 'meat'
        },
        {
          name: 'tom',
          age: 18,
          sex: 'man',
          score: 75,
          class: '3-4',
          girl: 'mary',
          book: 'hong',
          write: 'pencil',
          eat: 'meat'
        },
        {
          name: 'tom',
          age: 18,
          sex: 'man',
          score: 75,
          class: '3-4',
          girl: 'mary',
          book: 'hong',
          write: 'pencil',
          eat: 'meat'
        },
        {
          name: 'tom',
          age: 18,
          sex: 'man',
          score: 75,
          class: '3-4',
          girl: 'mary',
          book: 'hong',
          write: 'pencil',
          eat: 'meat'
        },
        {
          name: 'tom',
          age: 18,
          sex: 'man',
          score: 75,
          class: '3-4',
          girl: 'mary',
          book: 'hong',
          write: 'pencil',
          eat: 'meat'
        },
        {
          name: 'tom',
          age: 18,
          sex: 'man',
          score: 75,
          class: '3-4',
          girl: 'mary',
          book: 'hong',
          write: 'pencil',
          eat: 'meat'
        },
        {
          name: 'tom',
          age: 18,
          sex: 'man',
          score: 75,
          class: '3-4',
          girl: 'mary',
          book: 'hong',
          write: 'pencil',
          eat: 'meat'
        }
      ]
      let thead = document.getElementById('thead')
      let lefttds = document.getElementsByClassName('lefttd')
      let leftdiv = document.getElementById('left-div')
      div.addEventListener('scroll', function (e) {
        let scrollTop = this.scrollTop
        let scrollLeft = this.scrollLeft
        thead.style.transform = 'translateY(' + scrollTop + 'px)'
        leftdiv.style.top = scrollTop + 'px'
        leftdiv.style.left = scrollLeft + 'px'
        for (let i = 0, len = lefttds.length; i < len; i++) {
          lefttds[i].style.transform = 'translateX(' + scrollLeft + 'px)'
        }
      })
    }])
  </script>
</body>

</html>

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值