【问题标题】:How can I change CSS class name dynamically with reagent?如何使用试剂动态更改 CSS 类名?
【发布时间】:2017-06-13 23:40:08
【问题描述】:

关于reagent

我需要动态更改一些 CSS 类名。 我该怎么做?

示例代码在这里。

(defn app []
  (let [array [1, 2, 3]]
    (fn []
      [:div
       (for [index array]
         ;; I wanna change this classname like `item-1, item-2, ...`
         ^{:key index} [:div.i-wanna-change-this-classname-dynamically index])])))

【问题讨论】:

    标签: clojurescript reagent


    【解决方案1】:

    改变

    [:div.i-wanna-change-this-classname-dynamically index]
    

    [:div {:class (str “item-” index)} index]
    

    Reagent 提供了:div.class1.class2#id 的简写语法,但您也可以在映射中将它们设置为:div 之后向量中的第一项。

    还要记住 CSS :nth-child() 选择器是动态样式的另一个选项。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-23
      • 2021-08-18
      • 2017-02-09
      • 1970-01-01
      • 2016-08-12
      • 1970-01-01
      • 1970-01-01
      • 2014-04-29
      相关资源
      最近更新 更多