DAILY DOCDAILY DOC
Rust
Node
Notes
Ubuntu
Leetcode
  • it-tools
  • excalidraw
  • linux-command
Rust
Node
Notes
Ubuntu
Leetcode
  • it-tools
  • excalidraw
  • linux-command
  • BFC 块级格式化上下文
  • Note
  • WebAssembly
  • public api
  • 位运算
  • bitwise operator
  • css实现隐藏效果
  • css snippets
  • 抖音点赞
  • js 相等判断
  • fetch ReadableStream
  • git
  • Github Actions 工作流
  • google search
  • RPC vs HTTP
  • gravatar
  • hhkb
  • Init project
  • input 文件上传
  • mac

    • Mac 使用技巧
    • alfred
    • mac shortcuts
    • shortcuts text edit
    • mac 修改host
  • 微前端
  • mock
  • nginx dump
  • nginx
  • NirCmd
  • npm
  • Operator Precedence
  • package.json
  • url query 解析
  • pnpm
  • JavaScript Precise countdown
  • react 模版
  • regexp
  • setup web development
  • telegram

    • telegram bot
  • timeFunction ease
  • 视频裁剪
  • vscode

    • vscode 高级指南
    • bracketPairs
    • jsconfig.json
    • vscode pipe into code
    • social project
    • vscode tasks
  • draggable resizable
  • windows 激活
  • 前端截图实现
  • 文本配音 富文本实现
  • 图片处理
  • 前端坐标
  • 定时任务
  • work efficient
  • 微信小程序动画实现方案
  • 排列组合
  • 数列
  • 语音驱动文字
  • 浏览器
  • 状态管理
  • 移动盒子
  • 移动端开发常用snippets
  • 设计模式
  • web performance

视频裁剪

仅仅是模拟视频裁剪,获取到视频裁剪区域位置坐标,实际裁剪视频还是得依赖后端实现

dom模拟实现

video-cropper实现效果

元素选择框效果

主要依赖 css background 实现

.box {
    // 配置虚线背景 以及4条边框
    background-image: linear-gradient(to right, #fff 50%, transparent 50%), linear-gradient(to right, #fff 50%, transparent 50%), linear-gradient(to right, #fff, #fff), linear-gradient(to right, #fff, #fff);
    background-size: 10px 1px, 10px 1px, 100% 1px, 100% 1px;
    background-position: 0 calc(33.33% - 0.5px), 0 calc(66.66% - 0.5px), 0 0, 0 100%;
    background-repeat: repeat-x;
    &::before {
        content: '';
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;

        background-image: linear-gradient(to bottom, #fff 50%, transparent 50%), linear-gradient(to bottom, #fff 50%, transparent 50%), linear-gradient(to bottom, #fff, #fff), linear-gradient(to bottom, #fff, #fff);
        background-size: 1px 10px, 1px 10px, 1px 100%, 1px 100%;
        background-position: calc(33.33% - 1px) 0, calc(66.66% - 1px) 0, 0 0, 100% 0;
        background-repeat: repeat-y;
    }
}

mask遮罩区域

没想到吧,css background 一样能模拟出来

通过在盒子周围用4个背景拼接起来,形成一个整体的效果

    computed: {
        backgroundImage() {
      return `linear-gradient(to bottom, var(--main-bg-color) 0, var(--main-bg-color) ${
        this.top
      }px,transparent 0),linear-gradient(to top, var(--main-bg-color) 0, var(--main-bg-color) ${
        this.parentSize.height - this.bottom + 1
      }px, transparent 0),linear-gradient(to bottom,transparent ${0},transparent ${
        this.top
      }px, var(--main-bg-color) ${this.top}px, var(--main-bg-color) ${
        this.bottom
      }px , transparent 0),linear-gradient(to bottom, transparent ${0},transparent ${
        this.top
      }px, var(--main-bg-color) ${this.top}px, var(--main-bg-color) ${
        this.bottom - 1
      }px,transparent 0)`;
    },
    }

canvas 画布实现

通过canvas 可以轻易的实现该效果

原生canvas移动效果

建议通过 konva 实现,konva对canvas做了封住,更加易用

Last Updated:
Contributors: rosendo
Prev
timeFunction ease