better

日期:2021-02-28 类型:科技新闻 

关键词:在线编辑图片,什么软件可以抠图,在线图片,p图软件电脑版,在线抠图

1、基础应用

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF⑻">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <link href="https://unpkg.com/element-ui/lib/theme-chalk/index.css" rel="stylesheet">
  <style>
    *{
      margin: 0;
      padding: 0;
      border: 0;
      outline: none;
      font-family: Arial;
      list-style: none;
      -webkit-font-smoothing: antialiased;
    }
    html, body, #app{
      height: 100%;
    }
    #app{
      padding: 20px 0;
      box-sizing: border-box;
    }
    .wrapper{
      display: flex;
      height: 100%;
      overflow: hidden;
      max-width: 1200px;
      margin: 0 auto;
    }
    .menu{
      width: 100px;
      height: 100%;
      padding-right: 20px;
    }
    .content{
      flex: 1;
      height: 100%;
      overflow: hidden;
      position: relative;
    }
    .menu-item{
      margin-bottom: 10px;
    }
    .menu-item-content{
      width: 100%;
      padding: 7px 0;
      text-align: center;
      border: 1px solid #ddd;
      border-radius: 2px;
      color: #333;
      cursor: pointer;
    }
    .active{
      border-color: #409EFF;
      background: #409EFF;
      color: #fff;
    }
    .content-item{
      margin-bottom: 20px;
    }
    .content-item-text{
      border-radius: 2px;
      border: 1px solid #ddd;
    }
    .content-item-text>img{
      width: 100%;
      vertical-align: middle;
    }
  </style>
</head>
<body>
    <div id="app">
      <div class="wrapper">
        <div class="menu">
          <ul>
            <li class="menu-item" v-for="(item, index) in menu" :key="index" @click="handleClick(index)">
              <div class="menu-item-content" :class="{'active': getCurrentIndex() == index}" v-text="item.label"></div>
            </li>
          </ul>
        </div>
        <div class="content" ref="content">
          <ul>
            <li class="content-item" v-for="(item, index) in content" :key="index">
              <div class="content-item-text">
                <img :src="item" alt="">
              </div>
            </li>
          </ul>
        </div>
      </div>
    </div>
  <script src="https://cdn.jsdelivr.net/npm/better-scroll"></script>
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  <script src="https://unpkg.com/element-ui/lib/index.js"></script>
  <script>
    new Vue({
      el: '#app',
      data: {
        contentScroll: null,
        listHeight: [], // 用来储存每个子盒子的高宽比
        currentIndex: 0,
        scrollY: 0,
        menu: [
          {
            label: '照片1',
            id: 0,
          },
          {
            label: '照片2',
            id: 1,
          },
          {
            label: '照片3',
            id: 2,
          },
          {
            label: '照片4',
            id: 3,
          },
          {
            label: '照片5',
            id: 4,
          },
        ],
        content: [
          'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=43&di=d3d787658bd0b0f21d2459d90b3bd19b&imgtype=jpg&src=http%3A%2F%2Fimg4.imgtn.bdimg.com%2Fit%2Fu%三d1735688044%2C4235283864%26fm%三d214%26gp%三d0.jpg',
          'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=78&di=f46b69a4c2db2ba2f07f0fe1cc7af952&imgtype=0&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201210%2F04%2F202_NrBQG.jpeg',
          'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=19&di=122152eaee12d6ea019b2cec2b80e468&imgtype=0&src=http%3A%2F%2Fpic44.nipic.com%2F20140723%2F18505720_094503373000_2.jpg',
          'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=69&di=d33d35a826cc700add7b7bd53f9282c0&imgtype=0&src=http%3A%2F%2Fpic37.nipic.com%2F20140103%2F10616010_2_2.jpg',
          'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=91&di=ec438ea6559d06cc1a49a27b122e8edf&imgtype=0&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fblog%2F201312%2F09%2F202_evtcw.jpeg',
        ]
      },
      methods: {
        initScroll() {
          const content = this.$refs.content;
          this.contentScroll = new BScroll(content, {
            click: true, // 由于betterscroll默认设置会阻拦点一下恶性事件。这里要设定1下
            mouseWheel: true, // 电脑鼠标滚轮翻转
            probeType: 3,
            scrollY: true,
            scrollbar: {
              fade: true, // 是不是显示信息翻转条
              interactive: false, // 1.8.0 新增
            },
            preventDefault: false, // 阻拦了访问器默认设置选定个人行为
          });
          // 获得翻转的值,取值给scrollY
          this.contentScroll.on('scroll', pos => {
            this.scrollY = Math.abs(Math.round(pos.y));
          });
        },
        getCurrentIndex() {
          for (let i = 0; i < this.listHeight.length; i++) {
            const height = this.listHeight[i];
            const height1 = this.listHeight[i + 1];
            // 处理当翻转到最终时,內容不够盒子高宽比时,菜单显示信息难题。当翻转到最终,选定最终1个菜单
            // maxScrollY:最大纵向翻转部位
            if (Math.abs(this.contentScroll.maxScrollY) === Math.abs(this.scrollY)) {
              return this.content.length - 1;
            }
            if (!height1 || (this.scrollY < height1 && this.scrollY >= height)) {
              return i;
            }
          }
        },
        handleClick(index) {
          const content = this.$refs.content;
          const contentList = content.getElementsByClassName('content-item');
          const el = contentList[index];
          // scrollToElement:翻转到总体目标元素
          this.contentScroll.scrollToElement(el, 300);
        },
        getHeightList() {
          this.listHeight = [];
          let height = 0;
          this.listHeight.push(height);
          const content = this.$refs.content;
          const contentList = content.getElementsByClassName('content-item');
          for (let i = 0; i < contentList.length; i++) {
            const item = contentList[i];
            height += item.clientHeight;
            this.listHeight.push(height);
          }
          this.initScroll();
        }
      },
      mounted() {
        this.$nextTick(function() {
          // 因为照片太大,载入较为慢,导致都还没彻底载入完就原始化了,致使翻转不上,因此这里加个定时执行器延迟时间下
          setTimeout(() => {
            this.getHeightList();
          }, 400);
        });
      },
    });
  </script>
</body>
</html>

因为访问器的适配性,每一个访问器的翻转条款式都不尽同样,应用css款式改动的话,也仅有一部分访问器能做到你要想的实际效果。

better-scroll仿真模拟完成翻转条,父器皿设定固定不动高宽比,并设定特性 overflow:hidden,让子元素超过父器皿后掩藏,better-scroll功效在父器皿上,根据transform:translate特性来让子元素翻转到要想的地区。

以上便是本文的所有內容,期待对大伙儿的学习培训有一定的协助,也期待大伙儿多多适用脚本制作之家。