【React+Ts】窗口拖拽+放大缩小功能

tsx代码:

import React, { Component, RefObject } from 'react'

import './index.less'

interface Iprop { }
interface Istate {
    arr: arr[]
}
interface arr {
    id: symbol,
    txt: string
}
export default class index extends Component<Iprop, Istate> {
    constructor(props: Iprop) {
        super(props)
        this.state = {
            arr: [

            ]
        }
    }
    pw: number = 0;
    ph: number = 0;
    px: number = 0
    py: number = 0
    son?: HTMLDivElement
    gapW: number = 0
    p = React.createRef<HTMLDivElement>()
    direction: string = ''
    nowX: number = 0
    nowY: number = 0
    disx: number = 0
    disy: number = 0
    x: number = 0
    y: number = 0
    fnAlterS(e: React.MouseEvent) {
        this.pw = (e.target as HTMLDivElement).offsetWidth
        this.ph = (e.target as HTMLDivElement).offsetHeight
        this.px = (e.pageX - (e.target as HTMLDivElement).offsetLeft - this.pw / 2) * (this.pw > this.ph ? this.ph / this.pw : 1);
        this.py = (e.pageY - (e.target as HTMLDivElement).offsetTop - this.ph / 2) * (this.ph > this.pw ? this.pw / this.ph : 1);
        this.son = ((e.target as HTMLDivElement).children[0] as HTMLDivElement)
        this.gapW = (this.ph > this.pw ? this.pw : this.ph) / 2 - this.son.offsetLeft
        this.nowX = e.pageX
        this.nowY = e.pageY
        if (this.px <= -this.gapW && Math.abs(this.py) < this.gapW) {
            // 左边
            this.direction = '左'
        }
        if (this.px >= this.gapW && Math.abs(this.py) < this.gapW) {
            // 右边
            this.direction = '右'
      
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值