You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何自定义JSXGraph全屏模式以减少灰色边距?

解决JSXGraph全屏模式边距过大的问题
  • 初始化时配置绘图板参数
    直接在创建JSXGraph绘图板时,通过设置内部边距、边框和全屏专属参数来缩小灰色边距:

    const board = JXG.JSXGraph.initBoard('jxgbox', {
        boundingbox: [-10, 10, 10, -10], // 自定义绘图区域范围
        margin: 0, // 移除绘图板内部边距
        border: 0, // 去掉边框边距
        showNavigation: false, // 不需要导航栏的话可以关闭,进一步节省空间
        fullscreen: {
            margin: 0, // 单独指定全屏模式下的边距
            fillColor: '#ffffff' // 把默认灰色背景改成白色,消除边距视觉感
        }
    });
    
  • 用CSS覆盖默认全屏样式
    JSXGraph的全屏容器自带默认padding和margin,直接写CSS强制覆盖:

    .jxgbox.fullscreen {
        padding: 0 !important;
        margin: 0 !important;
    }
    .jxgbox.fullscreen .jxgcanvas {
        position: absolute;
        top: 0;
        left: 0;
        width: 100% !important;
        height: 100% !important;
    }
    
  • 动态适配全屏时的绘图区域
    监听全屏切换事件,进入全屏后重新计算绘图边界,让内容完全铺满屏幕:

    board.on('fullscreen', function(isFullscreen) {
        if (isFullscreen) {
            const screenW = window.innerWidth;
            const screenH = window.innerHeight;
            // 根据屏幕尺寸重新设置边界,确保内容占满全屏
            board.setBoundingBox([-screenW/20, screenH/20, screenW/20, -screenH/20]);
            board.zoomToFit();
        } else {
            // 退出全屏后恢复原有的绘图边界
            board.setBoundingBox([-10, 10, 10, -10]);
        }
    });
    

内容的提问来源于stack exchange,提问作者sacha friedli

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 15:01:05