我在一个标题中有两个图标,它们有下拉菜单,当单击时会切换。
在每个图标的每个列表项中都有一个'i‘标签,它是向下箭头的字体。当单击每个图标时,通过将类“fa-chevron-down”更改为“fa-chevron- up”,箭头将变为向上。
但是,如果我单击帮助图标,帮助下拉菜单将向下滑动,如果我单击篮子图标,帮助下拉菜单将向上滑动,篮子下拉菜单将向下滑动。相关图标中的箭头也需要随之更改-帮助图标上的箭头需要更改为向下,因此类需要从“fa-chevron-up”更改回“fa-chevron- down”。
例如,如果篮子下拉菜单是活动的,那么帮助图标'i‘标签应该有类’fa-chevron down‘,篮子图标'i’标签应该有类'fa-chevron-up‘。如果帮助下拉菜单是活动的,那么篮子图标'i‘标记应该有'fa-chevron-down’类,而帮助图标'i‘标记应该有'fa-chevron-up’类。
这是一个jsFiddle:http://jsfiddle.net/2srx4sv2/9/
代码是:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="format-detection=no,initial-scale=1.0,maximum-scale=1.0,user-scalable=0,width=device-width" />
<title>Untitled Document</title>
<link href="http://www.swimmingcover.co.uk/test_new/css/header.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="http://www.swimmingcover.co.uk/test_new/css/font-awesome.min.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>
<script src="http://www.swimmingcover.co.uk/test_new/js/mobile.js" type="text/javascript"></script>
</head>
<body>
<div id="header">
<ul class="hdr_link_icons">
<li class="icon_basket"><img src="http://www.swimmingcover.co.uk/test_new/images/header/icon_basket.jpg" alt="My basket" /><i class="fa fa-chevron-down"></i></li>
<li class="icon_help"><img src="http://www.swimmingcover.co.uk/test_new/images/header/icon_help.jpg" alt="Help Section" /><i class="fa fa-chevron-down"></i></li>
</ul>
<ul class="hdr_dropdown_area" id="help_dropdown">
<li><a href="">Your Account <span class="hdr_link_arrow">»</span></a></li>
<li><a href="">Corporate Sales <span class="hdr_link_arrow">»</span></a></li>
<li><a href="">Got a voucher? <span class="hdr_link_arrow">»</span></a></li>
</ul>
<div id="dvBasket" class="basketoverview hdr_dropdown_area">
<div class="heading">Total items: 1</div>
<div class="item">
<div class="details">
<a href="#">
Product 1
</a>
<br />
<span class="price">£39.00</span>
</div>
</div>
<div class="item">
<div class="details">
<a href="#">
Product 2
</a>
<br />
<span class="price">£39.00</span>
</div>
</div>
<div class="bottom">
<a title="Your basket" href="#">View Basket</a>
</div>
</div>
</div>
</body>
</html>发布于 2014-10-08 05:39:37
我更新了小提琴,你可以对每一个使用这一行
$(this).children(".fa-chevron-down, .fa-chevron-up").toggleClass( 'fa-chevron-down fa-chevron-up'); https://stackoverflow.com/questions/26245592
复制相似问题