简体   繁体   中英

How to add linear-gradient color to Slider?

I want to add linear-gradient to Material-UI Slider as color. Is it possible? I try everything.

color: 'linear-gradient(180deg, #29ABE2 0%, #00EAA6 100%)'

linear-gradient creates an image not a color. So you need to use it in CSS that specifies an image (eg background-image ).

Below is an example of a Slider using a gradient.

import React from "react";
import { makeStyles, withStyles } from "@material-ui/core/styles";
import Slider from "@material-ui/core/Slider";

const useStyles = makeStyles({
  root: {
    width: 200
  }
});

const CustomSlider = withStyles({
  rail: {
    backgroundImage: "linear-gradient(.25turn, #f00, #00f)"
  },
  track: {
    backgroundImage: "linear-gradient(.25turn, #f00, #00f)"
  }
})(Slider);

export default function ContinuousSlider() {
  const classes = useStyles();
  const [value, setValue] = React.useState(30);

  const handleChange = (event, newValue) => {
    setValue(newValue);
  };

  return (
    <div className={classes.root}>
      <CustomSlider
        value={value}
        onChange={handleChange}
        aria-labelledby="continuous-slider"
      />
    </div>
  );
}

编辑渐变滑块

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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