微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用@material-ui/core,我如何制作一个Slider,其中轨道被分成不同颜色的左右?

如何解决使用@material-ui/core,我如何制作一个Slider,其中轨道被分成不同颜色的左右?

滑块从 -10 变为 +10。从 -10 到 0,颜色应该是红色。从 0 到 +10,颜色应该是绿色。

如何使用 <Slider /> 中的 @material-ui/core 实现此目的?

解决方法

我不确定您指的是 info [sysup] ea4: repo already installed checkyum version 22.3 (excludes: bind-chroot kernel ruby) checkyum version 22.3 (excludes: bind-chroot kernel) info [sysup] Starting yum execution “--assumeyes --color=never --config /etc/yum.conf install ImageMagick-devel --enablerepo=powertools --enablerepo=epel”. Last metadata expiration check: 2:19:16 ago on Fri Jul 9 14:54:34 2021. Dependencies resolved. ================================================================================ Package Arch Version Repo Size ================================================================================ Installing: ImageMagick-devel x86_64 1:6.9.11.60-1.el8.remi remi 136 k Installing dependencies: ImageMagick x86_64 1:6.9.11.60-1.el8.remi remi 103 k ImageMagick-libs x86_64 1:6.9.11.60-1.el8.remi remi 2.4 M Transaction Summary ================================================================================ Install 3 Packages Total size: 2.7 M Installed size: 8.8 M Downloading Packages: [SKIPPED] ImageMagick-6.9.11.60-1.el8.remi.x86_64.rpm: Already downloaded [SKIPPED] ImageMagick-devel-6.9.11.60-1.el8.remi.x86_64.rpm: Already downloaded [SKIPPED] ImageMagick-libs-6.9.11.60-1.el8.remi.x86_64.rpm: Already downloaded Running transaction check Transaction check succeeded. Running transaction test The downloaded packages were saved in cache until the next successful transaction. You can remove cached packages by executing 'yum clean packages'. Error: Transaction test error: file /usr/bin/animate from install of ImageMagick-1:6.9.11.60-1.el8.remi.x86_64 conflicts with file from package ImageMagick7-7.1.0.2-1.el8.remi.x86_64 file /usr/bin/compare from install of ImageMagick-1:6.9.11.60-1.el8.remi.x86_64 conflicts with file from package ImageMagick7-7.1.0.2-1.el8.remi.x86_64 file /usr/bin/composite from install of ImageMagick-1:6.9.11.60-1.el8.remi.x86_64 conflicts with file from package ImageMagick7-7.1.0.2-1.el8.remi.x86_64 file /usr/bin/conjure from install of ImageMagick-1:6.9.11.60-1.el8.remi.x86_64 conflicts with file from package ImageMagick7-7.1.0.2-1.el8.remi.x86_64 file /usr/bin/convert from install of ImageMagick-1:6.9.11.60-1.el8.remi.x86_64 conflicts with file from package ImageMagick7-7.1.0.2-1.el8.remi.x86_64 file /usr/bin/display from install of ImageMagick-1:6.9.11.60-1.el8.remi.x86_64 conflicts with file from package ImageMagick7-7.1.0.2-1.el8.remi.x86_64 file /usr/bin/identify from install of ImageMagick-1:6.9.11.60-1.el8.remi.x86_64 conflicts with file from package ImageMagick7-7.1.0.2-1.el8.remi.x86_64 file /usr/bin/import from install of ImageMagick-1:6.9.11.60-1.el8.remi.x86_64 conflicts with file from package ImageMagick7-7.1.0.2-1.el8.remi.x86_64 file /usr/bin/mogrify from install of ImageMagick-1:6.9.11.60-1.el8.remi.x86_64 conflicts with file from package ImageMagick7-7.1.0.2-1.el8.remi.x86_64 file /usr/bin/montage from install of ImageMagick-1:6.9.11.60-1.el8.remi.x86_64 conflicts with file from package ImageMagick7-7.1.0.2-1.el8.remi.x86_64 file /usr/bin/stream from install of ImageMagick-1:6.9.11.60-1.el8.remi.x86_64 conflicts with file from package ImageMagick7-7.1.0.2-1.el8.remi.x86_64 file /usr/share/man/man1/ImageMagick.1.gz from install of ImageMagick-1:6.9.11.60-1.el8.remi.x86_64 conflicts with file from package ImageMagick7-7.1.0.2-1.el8.remi.x86_64 file /usr/share/man/man1/animate.1.gz from install of ImageMagick-1:6.9.11.60-1.el8.remi.x86_64 conflicts with file from package ImageMagick7-7.1.0.2-1.el8.remi.x86_64 file /usr/share/man/man1/compare.1.gz from install of ImageMagick-1:6.9.11.60-1.el8.remi.x86_64 conflicts with file from package ImageMagick7-7.1.0.2-1.el8.remi.x86_64 file /usr/share/man/man1/composite.1.gz from install of ImageMagick-1:6.9.11.60-1.el8.remi.x86_64 conflicts with file from package ImageMagick7-7.1.0.2-1.el8.remi.x86_64 file /usr/share/man/man1/conjure.1.gz from install of ImageMagick-1:6.9.11.60-1.el8.remi.x86_64 conflicts with file from package ImageMagick7-7.1.0.2-1.el8.remi.x86_64 file /usr/share/man/man1/convert.1.gz from install of ImageMagick-1:6.9.11.60-1.el8.remi.x86_64 conflicts with file from package ImageMagick7-7.1.0.2-1.el8.remi.x86_64 file /usr/share/man/man1/display.1.gz from install of ImageMagick-1:6.9.11.60-1.el8.remi.x86_64 conflicts with file from package ImageMagick7-7.1.0.2-1.el8.remi.x86_64 file /usr/share/man/man1/identify.1.gz from install of ImageMagick-1:6.9.11.60-1.el8.remi.x86_64 conflicts with file from package ImageMagick7-7.1.0.2-1.el8.remi.x86_64 file /usr/share/man/man1/import.1.gz from install of ImageMagick-1:6.9.11.60-1.el8.remi.x86_64 conflicts with file from package ImageMagick7-7.1.0.2-1.el8.remi.x86_64 file /usr/share/man/man1/mogrify.1.gz from install of ImageMagick-1:6.9.11.60-1.el8.remi.x86_64 conflicts with file from package ImageMagick7-7.1.0.2-1.el8.remi.x86_64 file /usr/share/man/man1/montage.1.gz from install of ImageMagick-1:6.9.11.60-1.el8.remi.x86_64 conflicts with file from package ImageMagick7-7.1.0.2-1.el8.remi.x86_64 file /usr/share/man/man1/stream.1.gz from install of ImageMagick-1:6.9.11.60-1.el8.remi.x86_64 conflicts with file from package ImageMagick7-7.1.0.2-1.el8.remi.x86_64 file /usr/bin/MagickCore-config from install of ImageMagick-devel-1:6.9.11.60-1.el8.remi.x86_64 conflicts with file from package ImageMagick7-devel-7.1.0.2-1.el8.remi.x86_64 file /usr/bin/MagickWand-config from install of ImageMagick-devel-1:6.9.11.60-1.el8.remi.x86_64 conflicts with file from package ImageMagick7-devel-7.1.0.2-1.el8.remi.x86_64 file /usr/lib64/pkgconfig/ImageMagick.pc from install of ImageMagick-devel-1:6.9.11.60-1.el8.remi.x86_64 conflicts with file from package ImageMagick7-devel-7.1.0.2-1.el8.remi.x86_64 file /usr/lib64/pkgconfig/MagickCore.pc from install of ImageMagick-devel-1:6.9.11.60-1.el8.remi.x86_64 conflicts with file from package ImageMagick7-devel-7.1.0.2-1.el8.remi.x86_64 file /usr/lib64/pkgconfig/MagickWand.pc from install of ImageMagick-devel-1:6.9.11.60-1.el8.remi.x86_64 conflicts with file from package ImageMagick7-devel-7.1.0.2-1.el8.remi.x86_64 info [sysup] Completed yum execution “--assumeyes --color=never --config /etc/yum.conf install ImageMagick-devel --enablerepo=powertools --enablerepo=epel”: in 4.886 second(s). (XID 7t4cua) “/usr/local/cpanel/scripts/retry_rpm” reported error code “1” when it ended: checkyum version 22.3 (excludes: bind-chroot ruby) E Sysup: Needed system RPMs were not installed: ImageMagick-devel 的 rail 元素还是 track 元素 - 本示例对两者都设置了样式。从本质上讲,这只是针对 Material-UI API 向您公开的正确类的一种情况。您可以获得 Slider 元素的类 here 的完整列表。

轨道的背景可以使用 CSS 生成的简单线性渐变图像进行样式设置,并且轨道本身可以通过将 prop 传递给 Slider 函数来有条件地设置样式:

makeStyles

从表面上看您的评论,您还可以将 import React from "react"; import Slider from "@material-ui/core/Slider"; import { makeStyles } from "@material-ui/core/styles"; const useStyles = makeStyles({ rail: { background: "linear-gradient(90deg,red 50%,green 50%)" },track: { background: ({ value }) => (value >= 0 ? "green" : "red") } }); const marks = Array.from({ length: 21 },(_,i) => ({ value: i - 10,label: i - 10 })); const App = () => { const [value,setValue] = React.useState(0); const classes = useStyles({ value }); return ( <Slider onChange={(e,newValue) => setValue(newValue)} max={10} min={-10} value={value} classes={classes} marks={marks} step={1} /> ); }; export default App; 道具传递给栏杆并有条件地设置样式。您永远不需要将轨道左侧的样式设置为灰色,因为在这种情况下它始终会被轨道上方覆盖:

value

否则,我会完全摆脱 rail: { background: ({ value }) => `linear-gradient(90deg,${value < 0 ? "gray" : "green"} 50%)` }, 元素并提高栏杆的不透明度,同时通过两个条件考虑两个不同的边:

track

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。