【问题标题】:Add css from controller SAPUI5从控制器 SAPUI5 添加 css
【发布时间】:2021-12-16 09:18:10
【问题描述】:

我正在尝试从我的控制器添加 css,因为我需要传递一些我在其中计算的数据,但我不知道这是否可能,我只能找到 javascript 的语法但 spaui5 不支持它。我正在尝试做的是以下内容:

var horaHand = that.getView().byId("horaHand");
var minutoHand = that.getView().byId("minutoHand");
var segundoHand = that.getView().byId("segundoHand");
                
var manillahora = hora + minuto/12; 
                
horaHand.css("transform", "rotate(" + manillahora + "deg)");
minutoHand.css("transform", "rotate(" + minuto + "deg)");
segundoHand.css("transform", "rotate(" + segundo + "deg)");

但它不起作用。有什么方法可以应用这个 css 吗?

我正在尝试的原始 javascript 代码是这样的:

const hourHand = document.querySelector('#hourHand');
const minuteHand = document.querySelector('#minuteHand');
const secondHand = document.querySelector('#secondHand');

hourHand.style.transform = `rotateZ(${(hours)+(minutes/12)}deg)`;
minuteHand.style.transform = `rotateZ(${minutes}deg)`;
secondHand.style.transform = `rotateZ(${seconds}deg)`;

或者这个

$('.hour-hand').css({
    'transform': `rotate(${hourDegrees}deg)`
  });

  $('.minute-hand').css({
    'transform': `rotate(${minuteDegrees}deg)`
  });

  $('.second-hand').css({
    'transform': `rotate(${secondDegrees}deg)`
  });

【问题讨论】:

    标签: javascript css model-view-controller controller sapui5


    【解决方案1】:

    我解决了这样的问题:

    $(".hora").css("transform", "rotate(" + hourDegrees + "deg)");
    $(".minuto").css("transform", "rotate(" + minuteDegrees + "deg)");
    $(".segundo").css("transform", "rotate(" + secondDegrees + "deg)");
    

    但众所周知,SAPUI5 css 只有在输入 !important 时才有效,因此上面的代码不起作用。你知道我怎样才能把 !important 放在控制器的代码中吗?我试过这样:$(".hora").css("transform", "rotate(" + hourDegrees + "deg) !important"); 但不起作用。

    【讨论】:

    • i.imgur.com/9raNzes.png 不知道为什么需要 !important。修改 UI5 CSS 时,我从来不需要 !important。
    猜你喜欢
    • 1970-01-01
    • 2016-05-29
    • 1970-01-01
    • 1970-01-01
    • 2021-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多