弹出框移动、放大、缩小、最大化处理

function getViewportSize() {
    //可视区域的宽度和高度
    return {
        width: document.documentElement.clientWidth,
        height: document.documentElement.clientHeight
    };
}

class LayerMove {
    /**
     * 弹层移动
     * @param $setCanMoveAreaName 鼠标点击哪个区域可以移动容器
     * @param $moveContainerName 要移动的容器
     */
    static execute($setCanMoveAreaName, $moveContainerName, $iframe) {
        let viewport = getViewportSize();
        $setCanMoveAreaName.mousedown(function (e) {
            e.stopPropagation();
            e.preventDefault();
            let x = e.clientX - $moveContainerName.offset().left;
            let y = e.clientY - $moveContainerName.offset().top;
            $(`#${$iframe}`).find('iframe')[0].contentWindow.init(x, y);
            $(document).mousemove(function (e) {
                let left = e.clientX - x;
                let top = e.clientY - y;
                let currentLeft = viewport.width - $moveContainerName.width();
                let currentTop = viewport.height - $moveContainerName.height();
                left = left < 0 ? 0 : left;
                left = left > currentLeft ? currentLeft : left;
                top = top < 0 ? 0 : top;
                top = top > currentTop ? currentTop : top;
                $moveContainerName.css({left: left + "px", top: top + "px"});
            });
            $(document).mouseup(function () {
                $(this).unbind("mousemove");
                $(`#${$iframe}`).find('iframe')[0].contentWindow.removeMouseMove();
                $(document).unbind("mouseup");
            });
        });
    }
}

/**
 *
 */
class LayerZoom {

    static execute($zoomContainerName, isEnlarge) {
        if (isEnlarge) {
            $zoomContainerName.css({position: "absolute", left: 0, top: 0, width: "100%", height: "100%"});
        } else {
            $zoomContainerName.css({position: "absolute", left: "15%", top: "15%", width: "70%", height: "70%"});
        }
    }

}

class LayerHandZoom {
    static execute($setCanZoomAreaName, $moveContainerName) {
        let viewport = getViewportSize();
        $setCanZoomAreaName.mousedown(function (e) {
            let x = e.clientX - $moveContainerName.width();
            let y = e.clientY - $moveContainerName.height();
            $(document).mousemove(function (e) {
                let width = e.clientX - x + "px";
                let height = e.clientY - y + "px";
                width = width < 0 ? 0 : width;
                width = width > viewport.width ? viewport.width : width;
                height = height < 0 ? 0 : height;
                height = height > viewport.height ? viewport.height : height;
                $moveContainerName.css({width: width, height: height});
            });
            $(document).mouseup(function () {
                $(document).unbind("mousemove");
            });
        });
    }
}

https://www.nowcoder.com

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
您可以使用Qt的QGraphicsView类来实现自由放大缩小弹出效果。下面是一个简单的示例代码: ```cpp #include <QtWidgets> class CustomGraphicsView : public QGraphicsView { public: CustomGraphicsView(QWidget* parent = nullptr) : QGraphicsView(parent) { setRenderHint(QPainter::Antialiasing); setDragMode(ScrollHandDrag); setTransformationAnchor(AnchorUnderMouse); setResizeAnchor(AnchorUnderMouse); } protected: void wheelEvent(QWheelEvent* event) override { // 获取滚轮滚动的角度 int angle = event->angleDelta().y(); // 根据滚动角度缩放视图 qreal scaleFactor = qPow(2, angle / 240.0); scale(scaleFactor, scaleFactor); } }; int main(int argc, char *argv[]) { QApplication app(argc, argv); // 创建主窗口 QMainWindow mainWindow; // 创建自定义的图形视图 CustomGraphicsView view; view.setRenderHint(QPainter::Antialiasing); view.setSceneRect(-200, -200, 400, 400); // 创建弹出窗口 QDialog dialog(&mainWindow); dialog.setWindowTitle("弹出"); QVBoxLayout layout(&dialog); layout.addWidget(&view); dialog.setLayout(&layout); // 在主窗口中添加按钮,点击按钮弹出 QPushButton button("弹出", &mainWindow); QObject::connect(&button, &QPushButton::clicked, [&dialog]() { dialog.exec(); }); // 在主窗口中布局按钮 QWidget centralWidget(&mainWindow); QVBoxLayout centralLayout(&centralWidget); centralLayout.addWidget(&button); mainWindow.setCentralWidget(&centralWidget); mainWindow.show(); return app.exec(); } ``` 这个示例代码中,我们使用了QGraphicsView来创建一个自定义的图形视图类CustomGraphicsView。在CustomGraphicsView中,我们重写了wheelEvent函数来捕获滚轮事件,并根据滚轮的角度来缩放视图。 然后,我们创建了一个主窗口,并在主窗口中添加一个按钮。点击这个按钮会弹出一个包含自定义图形视图的弹出弹出中的图形视图可以通过滚轮进行自由放大缩小操作。 您可以根据自己的需求对示例代码进行修改和扩展。希望对您有帮助!
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

愤怒的小青春

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值