简体   繁体   English

在氚中,我该如何进行数学运算?

[英]In tritium, how can I do math operations?

I am transforming a website that contains elements with inline styles with fixed width and heights in pixels, like this: 我正在改造一个网站,其中包含具有固定宽度和高度(像素)的内联样式的元素,如下所示:

<div id="row1_column1" class="one-column" style="width:728px;height:1px;">  
    ...
</div>

I would like to create a function that transforms a fixed pixel dimension (eg, 768px) into a relative value (eg, 75%) based on a maximum value. 我想创建一种函数,该函数基于最大值将固定像素尺寸(例如,768px)变换为相对值(例如,75%)。 I would like to write it this way: 我想这样写:

@func XMLNode.relativize_fixed_dimensions(Number %full_width, Number %full_height) {
    attribute("style") {
        value() {
            replace(/width:\s*(\d)+px/) {
                set(concat("width:", (%1 / %full_width), "%"))
            }
            replace(/height:\s*(\d)+px/) {
                set(concat("height:", (%1 / %full_height), "%"))
            }
        }
    }
}

However, as per the moovweb documentation , there is no type such as Number, and no operators such as / either. 但是,根据moovweb文档 ,没有类型如Number,也没有诸如/之类的运算符。

What I'd like to know is: is it possible to do mathematical transformations in tritium so I can achieve what I need? 我想知道的是:是否可以在氚中进行数学变换,以便实现我的需要?

Unfortunately, there's no way to do this as of today. 不幸的是,到目前为止还没有办法做到这一点。 There is no way to perform a numerical expression on tritium. 无法在氚上执行数值表达式。 I believe this is in the roadmap for the future, but not sure when it would become a feature. 我相信这是未来的路线图,但不确定它什么时候会成为一个功能。

What I would suggest is to implement the change using javascript for now. 我建议现在使用javascript实现更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM