8.1贝塞尔曲线(下坡)绘制,自适应宽高、点位计算

 效果如下

左上角左边为(0,0)

右下角为(width,height)

// 根据宽高绘制贝塞尔曲线(下坡)
export function paintCurve(w, h) {
  let path = ''
  if (/^\d+$/.test(w) && /^\d+$/.test(w)) {
    let fontSize = document.getElementsByTagName('html')[0].style.fontSize
    fontSize = fontSize.split('px')[0]
    let halfWidth = Math.ceil((w / 75) * fontSize)
    let Width = Math.ceil((w / 37.5) * fontSize)
    let height = Math.ceil((h / 37.5) * fontSize)
    // L 0,Width的 意思是从横坐标0到Width这个区间把曲线绘制出来
    path = 'path("M 0,0 C ' + halfWidth + ',0 ' + halfWidth + ',' + height + ' ' + Width + ',' + height + ' ' + 'L 0,' + Width + ' Z")'
  } else {
    Toast('宽高必须为数字')
  }
  
  return path
}

在vue中使用

在style标签里,通过v-bind可以把data的变量绑定使用,然后通过计算出需要的点位,这里是根据自适应的根标签字体大小来实现根据屏幕自适应曲线位置

data() {
  return {
   // 贝塞尔曲线
   path: 'path("M 0,0 C 14,0 14,28 28,28 L 0,28 Z")'
  }
},
mounted() {
  // 绘制曲线
  this.path = paintCurve('28','28')   
},
<style lang="less" scoped>
.curve:after {
      content: '';
      position: absolute;
      width: 28px;
      height: 28px;
      top: 0;
      right: -27px;
      background: linear-gradient(to bottom, #0F1214,#383A3B);
      // clip-path: path('M 0,0 C 14,0 14,28 28,28 L 0,28 Z');
      clip-path: v-bind(path);
    }
}
</style>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值