gpt4 book ai didi

javascript - 切换 Material 设计图标

转载 作者:行者123 更新时间:2023-11-29 20:49:34 24 4
gpt4 key购买 nike

    $.fn.extend({
treed: function (o) {

var openedClass = 'glyphicon-minus-sign';
var closedClass = 'glyphicon-plus-sign';

var openedIconClass = 'keyboard_arrow_down';
var closedIconClass = 'keyboard_arrow_up';

if (typeof o != 'undefined'){
if (typeof o.openedClass != 'undefined'){
openedClass = o.openedClass;
}
if (typeof o.closedClass != 'undefined'){
closedClass = o.closedClass;
}
};

//initialize each of the top levels
var tree = $(this);
tree.addClass("tree");
tree.find('li').has("ul").each(function () {
$('.material-icons').css('display', 'block');
var branch = $(this); //li with children ul
branch.prepend("<i class='indicator glyphicon " + closedClass + "'></i>");
branch.addClass('branch');

branch.on('click', function (e) {

$('.material-icons').toggleClass("display-block");
$(this).toggleClass("orange-light");
if($(this).hasClass("orange-light")){
$(".arrow", this).text('keyboard_arrow_up');
}
if (this == e.target) {

var icon = $(this).children('i:first');
console.log(icon.text);
icon.toggleClass(openedClass + " " + closedClass);
icon.toggleClass(openedIconClass + " " + closedIconClass);
$(this).children().children().toggle();

}
})
branch.children().children().toggle();
});
//fire event from the dynamically added icon
tree.find('.branch .indicator').each(function(){
$(this).on('click', function () {
$(this).closest('li').click();
});
});
//fire event to open branch if the li contains an anchor instead of text
tree.find('.branch>a').each(function () {
$(this).on('click', function (e) {
$(this).closest('li').click();
e.preventDefault();
});
});
//fire event to open branch if the li contains a button instead of text
tree.find('.branch>button').each(function () {
$(this).on('click', function (e) {
$(this).closest('li').click();
e.preventDefault();
});
});
}
});

//Initialization of treeviews

$('#tree1').treed();

$('#tree2').treed({openedClass:'glyphicon-folder-open', closedClass:'glyphicon-folder-close'});

$('#tree3').treed({openedClass:'glyphicon-chevron-right', closedClass:'glyphicon-chevron-down'});
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<!DOCTYPE html>
<html>


<style type="text/css">
.tree, .tree ul {
margin:0;
padding:0;
list-style:none
}
.tree ul {
margin-left:1em;
position:relative
}
.tree ul ul {
margin-left:.5em
}

.tree ul:before {
content:"";
display:block;
width:0;
position:absolute;
top:18px;
bottom:16px;
left:40px;
border-left:1px solid;
border-color: #556f7b;
}
.tree li {
margin:0;
padding:0 1em;
line-height:2em;

position:relative;
font-family: Roboto;
font-size: 14px;
font-weight: 500;
font-style: normal;
font-stretch: normal;
letter-spacing: normal;
text-align: left;
color: #000000;
}
.tree ul li:before {
content:"";
display:block;
width:10px;
height:0;
border-top:1px solid;
margin-top:-1px;
position:absolute;
top:32px;
left:40px;
border-color: #556f7b;
}
.tree ul li:last-child:before {
background:#fff;
height:auto;
top:32px;
bottom:0
}

.indicator {
margin-right:5px;
}
.tree li a {
text-decoration: none;
font-family: Roboto;
font-size: 14px;
font-weight: 500;
font-style: normal;
font-stretch: normal;
letter-spacing: normal;
text-align: left;
color: #000000;
}
.tree li button, .tree li button:active, .tree li button:focus {
text-decoration: none;
color:#369;
border:none;
background:transparent;
margin:0px 0px 0px 0px;
padding:0px 0px 0px 0px;
outline: 0;

}

.branch{

height: 64px;
border-radius: 2px;
box-shadow: 0 0 2px 0 rgba(0, 0, 0, 0.12), 0px 2px 2px 0 rgba(0, 0, 0, 0.15);
border: solid 1px transparent;
padding-top: 18px!important;
cursor: pointer;
}
.indicator{
color: transparent;
margin-left: 5px;
margin-right: 5px;
}
.first-level .branch{
padding-left: 40px;
margin-bottom: 6px;
}
.orange-light{
background: #fff4e7;
}
.display-block{
display:block!important;
}
</style>
<body id="admin-body">
<div class="row">
<div class="col-md-2" id="sidebar-content">

</div>

<div class="col-md-10" id="main-content">
<ul id="tree2">
<li><a href="#">Level

<i class="material-icons arrow" style="float: right; padding-left: 24px; padding-right: 8px; color: #556f7b; display: block!important;">
keyboard_arrow_down
</i>

</a>
<a href="">
<i class="material-icons" style="float: right; padding-left: 28px;color: #f8971c; display: block!important; padding-right: 28px;
border-right: 1px solid #e8e8e8;">
send
</i>
</a>
<a href="">
<i class="material-icons" style="float: right; color: #556f7b; padding-right: 28px;
border-right: 1px solid #e8e8e8; display: block!important;">
list
</i>
</a>




<ul class="first-level" style=" margin-top: 22px; margin-left: -15px; margin-right: -15px;">
<li>faef
<ul>
<li>Reports
<ul>
<li>Report1</li>
<li>Report2</li>
<li>Report3</li>
</ul>
</li>

</ul>
</li>
<li>afasf
<ul>
<li>Reports
<ul>
<li>Report1</li>
<li>Report2</li>
<li>Report3</li>
</ul>
</li>

</ul>
</li>

</ul>




</li>

</ul>
</div>

</div>
</body>
</html>

我这里有这段代码和箭头 Material 设计图标的一部分,我设法通过点击使箭头向上,但是当我再次点击卡片时,图标不会切换。有人可以帮我解决这个问题吗..?我怎样才能切换 Material 设计图标有没有办法,如果可以的话你能帮我吗我是编码方面的新手,我正在尝试这里的一切,但它就是行不通

最佳答案

如您所见,您只需更改元素文本即可更改 Material Design 图标。您可以自由更改它,并且每次都有效。

似乎您的代码需要拆分成更小的函数,以便您找出错误所在。

$(window).on('click', function(event) {
var icon = $('.arrow');
icon.toggleClass('up');
if ( icon.hasClass('up') ) {
icon.text('keyboard_arrow_down');
} else {
icon.text('keyboard_arrow_up');
}
});
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">

<i class="material-icons arrow up">keyboard_arrow_down
</i>

关于javascript - 切换 Material 设计图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52605575/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com