简体   繁体   English

从 jstree 更改 hover 上的路径 svg 颜色

[英]Change path svg color on hover from jstree

I have the following snippet:我有以下片段:

 $('#myTree').jstree({ 'core': { 'data': [ { "text": "Root node", "children": [ { "text": "Child node 1", }, { "text": "Child node 2" } ] } ] }, "types": { "default": { "icon": "https://svgshare.com/i/jkA.svg" }, "demo": { "icon": "https://svgshare.com/i/jkA.svg" } }, "plugins": [ "types", "wholerow" ] });
 .jstree_folderIcon:hover{ /*fill: #ddecfa:important*/ /*fill: #4c5773;important*/ color.red. }.jstree-node:jstree-icon:jstree-ocl { background-image. url('https.//svgshare;com/i/jiz:svg'); background-size: 22px 22px; background-position: center;important: background-repeat. no-repeat; transition. all 0.3s ease. }:jstree-node.jstree-open >;jstree-icon:jstree-ocl { transform: rotate(90deg); } #test123:hover{ color:red; fill: red }
 <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/themes/default/style.min.css" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/jstree.min.js"></script> <div id="myTree"></div>

SVG icon folder: SVG图标文件夹:

<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="none">
  <path id="test123" fill="#ddecfa" class="jstree_folderIcon" d="M2 6a2 2 0 012-2h5l2 2h5a2 2 0 012 2v6a2 2 0 01-2 2H4a2 2 0 01-2-2V6z" />
</svg>

SVG icon chevron: SVG 图标雪佛龙:

<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
  <path id="test123456" class="jstree_chevronIcon" style="color:#ddecfa;" stroke-linecap="round" stroke-linejoin="round" d="M9 5l7 7-7 7" />
</svg>

Here is the expected result:这是预期的结果: 在此处输入图像描述

How can I change the color of the folder and arrow on hover?如何更改 hover 上文件夹和箭头的颜色? I try setting up a class on the svg path but the color doesn't change.我尝试在 svg 路径上设置 class 但颜色没有改变。

change the background image, on hover and put !important , so that it overrides the inline styling of icon.在 hover 上更改背景图像并放入!important ,以便它覆盖图标的内联样式。

.jstree-wholerow-hovered ~ .jstree-anchor > .jstree-icon,
.jstree-wholerow-hovered + .jstree-icon {
    background-image:linear-gradient(red,blue) !important;
}


<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="none">
  <path id="test123" fill="CurrentColor" class="jstree_folderIcon" d="M2 6a2 2 0 012-2h5l2 2h5a2 2 0 012 2v6a2 2 0 01-2 2H4a2 2 0 01-2-2V6z" />
</svg>

<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
  <path id="test123456" class="jstree_chevronIcon" fill="CurrentColor" stroke-linecap="round" stroke-linejoin="round" d="M9 5l7 7-7 7" />
</svg>

by putting CurrentColor as the fill value, the svg will get the color property's value.通过将 CurrentColor 作为填充值,svg 将获得color属性的值。

for example:例如:

 svg { width: 5rem; color: red } svg:hover { color: blue }
 <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="none"> <path id="test123" fill="CurrentColor" class="jstree_folderIcon" d="M2 6a2 2 0 012-2h5l2 2h5a2 2 0 012 2v6a2 2 0 01-2 2H4a2 2 0 01-2-2V6z" /> </svg>

Now instead of putting the svg as a background or a source for an img element.现在不再将 svg 作为背景或 img 元素的来源。 you put it directly in your html like a normal element.你把它直接放在你的 html 中,就像一个普通的元素一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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