首页 > 其他分享 >【快应用】如何动态设置渐变色样式

【快应用】如何动态设置渐变色样式

时间:2022-08-26 09:02:16浏览次数:95  
标签:linear 样式 渐变色 yellow gradient background 动态

 现象描述:

快应用中在<template>动态设置渐变色样式不生效,问题代码如下:

<div class="wrapper" style="background:linear-gradient({{gradient}});"></div>

 

问题分析

快应用中渐变色样式不支持在style中绑定变量来动态修改.

 

解决方法

可以通过动态改变class类名的方式来设置渐变色样式。

 

示例代码

<template>

  <!-- Only one root node is allowed in template. -->

  <div class="container">

    <div class="{{gradient}}">

      <text class="title">{{ gradient }}</text>

    </div>

    <input class="button" type="button" onclick="click($idx)" value="{{$item}}" for="{{list}}" />

  </div>

</template>

 

<style>

  .container {

    flex-direction: column;

    justify-content: center;

    align-items: center;

  }

  .button {

    width: 250px;

    margin-top: 10px;

    background-color: #00ced1;

    border-radius: 10px;

  }

  .redtoblue {

    background: linear-gradient(red, blue);

  }

  .redtogreen {

    background: linear-gradient(red, green);

  }

  .bluetogreen {

    background: linear-gradient(blue, green);

  }

  .redtoyellow {

    background: linear-gradient(red, yellow);

  }

  .yellowtogreen {

    background: linear-gradient(yellow, green);

  }

  .bluetoyellow {

    background: linear-gradient(blue, yellow);

  }

  .title {

    font-size: 100px;

  }

</style>

 

<script>

  module.exports = {

    data: {

      gradient: 'redtoblue',

      list: ["redtogreen", "bluetogreen", "redtoyellow", "yellowtogreen", "bluetoyellow", "redtoblue"]

    },

    onInit() {

      this.$page.setTitleBar({

        text: 'menu',

        textColor: '#ffffff',

        backgroundColor: '#007DFF',

        backgroundOpacity: 0.5,

        menu: true

      });

    },

    click(index) {

      this.gradient = this.list[index]

    }

  }

</script>

 

实现效果如下:

cke_721.png

欲了解更多更全技术文章,欢迎访问https://developer.huawei.com/consumer/cn/forum/?ha_source=zzh

标签:linear,样式,渐变色,yellow,gradient,background,动态
From: https://www.cnblogs.com/developer-huawei/p/16626422.html

相关文章

  • ABP-VNEXT 学习笔记(五)动态API客户端
    本篇内容需要结合上一篇  https://www.cnblogs.com/fei686868/p/16625289.html官方地址:https://docs.abp.io/zh-Hans/abp/latest/API/Dynamic-CSharp-API-Clients在上......
  • 关于ElementUI的el-popover的问题:文本换行、修改样式
     一、 el-popover组件要想实现content中的内容换行可是使用如下方法:第一种方法:<el-popoverplacement="right"width="370"trigger="h......
  • antdesign vue中写了样式不加载的解决方法
    在vue组件里,lang设置为less,在style设置为scoped的时候,在写样式有时候对子组件不生效。如果想让某些样式对子组件生效,可以使用/deep/深度选择器。代码:/deep/.ant-men......
  • 动态路由
    在路由配置里面,路径后面加/:值,那么路径就会有了参数例子:{name:'home',path:'/home/:abc',component:Home}<router-linkto="/home/875">Home</......
  • 自定义滚动条样式不生效:横轴设置 height,纵轴设置 width
    问题在修改滚动条样式时,两个类名,一个地方生效,另一个地方不生效。解决办法捣鼓很久才发现,原来横轴要设置height,纵轴要设置width。//滚动条的样式,高宽分别对应横竖......
  • IFC中的样式项(IfcStyledItem)
    IfcStyledItem保存构件的样式信息,可以分配给为IfcShapeRepresentation,也可以分配给IfcMaterialDefinitionRepresentation 。IfcStyledItem的两个用法示例:(1......
  • JavaScript中改变鼠标指针样式的方法
    JavaScript中改变鼠标指针样式的方法    在js中我们可以通过style对象的cursor属性来设置鼠标指针的样式,例varbody=document.querySelector("body") body.style......
  • ctfhub Linux动态加载器无x权限执行elf文件
    动态库链接器/加载器   当需要动态链接的应用被操作系统加载时   系统必须要定位然后加载它所需要的所有动态库文件   在Linux环境下,这项工作是由ld-linux.so.......
  • 动态规划——leetcode55、跳跃游戏
    题目描述: 解题方法:动态规划动态规划解题步骤:确定状态:最后一步:如果能跳到最后一个下标,我们考虑他的最后一步到n-1(最后一个下标),这一步是从i跳过......
  • C++ 静态库、动态库使用Cmake构建系统
    案例1:无静态库、动态库参与文件目录结构1假设include目录存放头文件data.h包含函数声明,src目录存放对应的data.cpp文件包含函数定义、以及一个全局变量。main.cpp存放在......