<!DOCTYPE html>
<html>
<head>
<title> new document </title>
<meta charset="utf-8">
<style>
a { text-decoration: none; color: #000; line-height: 2em; }
ul { list-style:none; padding: 0 0 0 20px; }
.affix { float: left; border: 1px solid #aaa; width: 150px; }
.affix .active a{ color: #e4393c; font-weight: bold; }
.container { float: left; width: 550px; min-height: 400px; border: 1px solid #aaa; }
.container .box { display: none; min-height: 300px; }
.container .box.active { display: block; }
</style>
</head>
<body>
<h1>练习:查找元素&操作元素</h1>
<h3>使用附加导航(affix)实现内容切换</h3> <div class="affix">
<ul>
<li><a data-toggle="item" href="#my-order">我的订单</a></li>
<li class="active"><a data-toggle="item" href="#user-setting">用户设置</a></li>
<li><a data-toggle="item" href="#account-security">账户安全</a></li>
</ul>
</div> <div class="container">
<div id="my-order" class="box" style="background:#fee">我的订单的详细内容</div>
<div id="user-setting" class="box active" style="background:#efe">用户设置的详细内容</div>
<div id="account-security" class="box" style="background:#eef">账户安全的详细内容</div>
</div>
<script src="js/jquery-1.11.3.js"></script>
<script>
//让所有data-toggle为item的元素都能响应单击事件
$("div.affix>ul").on(
"click","[data-toggle='item']",function(e){
//获得目标元素封装为jQuery对象
var $target=$(e.target);
//如果当前a的父元素不是active的
if(!$target.parent().hasClass("active")){
//获得当前a的父元素的所有兄弟中class为active的,移除其active类
$target.parent()
.siblings(".active")
.removeClass("active");
//为当前a的父元素添加active类
$target.parent().addClass("active");
//获得当前a的href属性,保存在变量selector中
//使用selector查找div,为其添加active类,再查找其所有兄弟中class为active的移除active类
$($target.attr("href"))
.addClass("active")
.siblings(".active")
.removeClass("active");
}
});
</script>
</body>
</html>

使用附加导航(affix)实现内容切换的更多相关文章

  1. Bootstrap 附加导航(Affix)插件

    bootstrap 附加导航(Affix)插件允许某个div元素固定到页面中的某个位置.您可以打开或关闭使用该插件之间进行切换 后续再写

  2. bootstrap的 附加导航Affix导航 (侧边窄条式 滚动监控式导航) 附加导航使用3.

    affix: 意思是粘附, 附着, 沾上. 因此, 附加导航就是 bootstrap的 Affix.js组件. bootstrap的 附加导航, 不是说导航分成主导航, 或者什么 副导航的 而是指, ...

  3. Bootstrap Affix(附加导航(Affix)插件的用法)

    原文网址:http://www.runoob.com/bootstrap/bootstrap-affix-plugin.html Bootstrap 附加导航(Affix)插件 附加导航(Affix) ...

  4. 附加导航(Affix)行为

    用法 通过 data 属性:如需向元素添加附加导航(Affix)行为,只需要向需要监听的元素添加 data-spy="affix" 即可.请使用偏移来定义何时切换元素的锁定和移动. ...

  5. Bootstrap-Plugin:附加导航(Affix)插件

    ylbtech-Bootstrap-Plugin:附加导航(Affix)插件 1.返回顶部 1. Bootstrap 附加导航(Affix)插件 附加导航(Affix)插件允许某个 <div&g ...

  6. Bootstrap 附加导航(Affix)插件

    附加导航(Affix)插件允许指定 <div> 固定在页面的某个位置.一个常见的例子是社交图标.它们将在某个位置开始,但当页面点击某个标记,该 <div> 会锁定在某个位置,不 ...

  7. jQuery实现页面导航内容定位效果,并支持内容切换

    需求 页面向下滚动时,需要将顶部的搜索栏信息和导航菜单吸顶,并且,搜索栏信息和导航菜单之间可以切换. 效果 https://www.iguopin.com/index.php?m=&c=ind ...

  8. 第二百四十九节,Bootstrap附加导航插件

    第二百四十九节,Bootstrap附加导航插件 学习要点: 1.附加导航插件 本节课我们主要学习一下 Bootstrap 中的附加导航插件 一.附加导航 注意:此插件要使用 bootstrap3.0. ...

  9. Bootstrap 学习笔记13 附加导航插件

    附加导航代码: <style> a:focus { outline: none; } .nav-pills { width: 150px; } .nav-pills.affix { top ...

随机推荐

  1. theano中的logisticregression代码学习

    1 class LogisticRegression (object): 2 def __int__(self,...): 3 4 #定义一些与逻辑回归相关的各种函数 5 6 def method1( ...

  2. www.nygwkt.com

    南京宁阳制冷设备维修有限公司是专业从事厨房空调,http://www.nygwkt.com岗位空调制冷设备设计.制造.安装.改造.维修.保养的专业化公司.在南京享有很高的客户评论. 我们对南京宁阳制冷 ...

  3. Rails中的测试RSpec升级遇到的问题

    bundle exec rspec spec/ /home/wuxj/Prac/rrprac/sample_app/spec/spec_helper.rb::in `block in <top ...

  4. SAP Crystal Dashboard Design 2011 win7 x64 安装

    suggest: unZip the setup package to C:\dashboard\  (make sure that the path cannot contain non-unico ...

  5. app内购提示,您已购买此商品,但未下载

    出现这样的问题,是支付没有finish造成的,一般在支付过程中断网了,下次再购买同一商品的时候就会出现这样的问题, 解决办法,在点击购买的时候判断支付队列中是否有为finish的商品,若有,则进行处理 ...

  6. Github、Jekyll 搭建及优化静态博客方法指南

    尝试自己写 Blog 的人,一般会经历三个阶段. 第一阶段,刚接触 Blog,觉得很新鲜,试着选择一个免费空间来写. 第二阶段,发现免费空间限制太多,就自己购买域名和空间,搭建独立博客. 第三阶段,觉 ...

  7. windows提权操作以及系统开机关机重启代码(用到了LookupPrivilegeValue和AdjustTokenPrivileges调整进程的Token权限)

    对于UAC提权操作,一般在编译期间,如果程序有需求要提权,会在编译器里设置,vs2010比较简单,在工程属性里可以直接设置,vs2005稍微有点儿麻烦,参考这篇文章: http://www.seany ...

  8. Android4.0窗口机制和创建过程分析

    一  前言 在谈到这个话题的时候,脑海里面千头万绪,因为它涉及到了方方面面的知识… 比如Activity管理,窗口添加,Token权限验证等等… 既然这么复杂,那么我们就复杂的问题简单化,可以分成下面 ...

  9. 【CF】270D Design Tutorial: Inverse the Problem

    题意异常的简单.就是给定一个邻接矩阵,让你判定是否为树.算法1:O(n^3).思路就是找到树边,原理是LCA.判断树边的数目是否为n-1.39-th个数据T了,自己测试2000跑到4s.算法2:O(n ...

  10. WordPress HMS Testimonials 多个跨站脚本漏洞和跨站请求伪造漏洞

    漏洞名称: WordPress HMS Testimonials 多个跨站脚本漏洞和跨站请求伪造漏洞 CNNVD编号: CNNVD-201308-199 发布时间: 2013-08-22 更新时间: ...