描述

AE自带的缩放除了自适应,只有33%,50%,100%。想取中间值非常费劲

源码

//视图无级缩放 v1.0.0 2021-08-06
//Raymond Yan 2021 (RaymondClr@outlook.com / QQ: 1107677019)

var win = new Window(
    "palette { margins: 5, spacing: 5, orientation: 'row', \
        A: Button { size: [25, 25] text: '小' }, \
        B: Slider { size: [150, 25], minvalue: 1, maxvalue: 100 }, \
        C: Button { size: [25, 25] text: '大' },\
    }"
);
win.show();

var btn_zoomIn = win.A;
var sld_zoomRatio = win.B;
var btn_zoomOut = win.C;

var g_zoomScaleStep = 5;
var g_magnification = 50;

(function initViewZoom() {
    var zoomScale = app.activeViewer ? app.activeViewer.views['0'].options.zoom : g_magnification / 100;
    g_magnification = sld_zoomRatio.value = zoomScale > 1 ? 100 : zoomScale * 100;
})();

btn_zoomIn.onClick = zoomCompView(0, sld_zoomRatio, g_zoomScaleStep);
btn_zoomOut.onClick = zoomCompView(1, sld_zoomRatio, g_zoomScaleStep);
sld_zoomRatio.onChange = sld_zoomRatio.onChanging = zoomCompView(2, sld_zoomRatio);

function zoomCompView(modeIndex, scriptUiSliderControl, step) {
    var zoomStrategies = [
        function (value, step) {
            var scale = Math.ceil(Math.ceil(value) / step) * step - step;
            return scale < 1 ? 1 : scale;
        },
        function (value, step) {
            var scale = Math.floor(Math.floor(value) / step) * step + step;
            return scale > 100 ? 100 : scale;
        },
        function (value) {
            return Math.floor(value * 100) / 100;
        },
    ][modeIndex];
    return function () {
        if (!app.activeViewer) return (scriptUiSliderControl.value = g_magnification);
        var zoomScale = zoomStrategies(scriptUiSliderControl.value, step);
        app.activeViewer.views['0'].options.zoom = zoomScale / 100;
        g_magnification = scriptUiSliderControl.value = zoomScale;
    };
}

 

您的电子邮箱地址不会被公开。 必填项已用*标注

请下载到本地观看!因为pdf是用的阿里云盘预览,可能部分字体加载不了。

请安装油猴脚本,并下载月离的万事屋脚本。详情请查看菜单 导航 - 用户指引

请在右上角三个点 - 下载管理 - 找到刚才的文件,选择允许下载。 或者换个浏览器