jQuery实现的滑块滑动导航效果示例


Posted in jQuery onJune 04, 2018

本文实例讲述了jQuery实现的滑块滑动导航效果。分享给大家供大家参考,具体如下:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>3water.com jquery滑动导航</title>
  <style>
    *{margin: 0;padding: 0;box-sizing: border-box;-moz-box-sizing: border-box;}
    body {
      font: 16px/20px 'Microsoft yahei,微软雅黑';
      color: #AFBBBB;
    }
    ul {
      list-style-type: none;
    }
    ul li {
      float: left;
    }
    a {
      text-decoration: none;
      color: #AFBBBB;
    }
    a:hover {
      color: #ffffff;
      cursor: pointer;
    }
    .clearfix:before,.clearfix:after {
      content:"";
      clear: both;
      display: table;
      height: 0;
      zoom: 1;
      overflow: hidden;
    }
    .nav {
      width:519px;
      margin: 0 auto;
    }
    .nav ul {
      background: gray;
      height: 35px;
      line-height: 35px;
      position: relative;
      padding: 0 5px;
    }
    .nav ul li {
      position: relative;
      padding: 0 25px;
    }
    .nav ul li>a {
      position: relative;
      z-index: 100; /*将a元素的z-index设置比li大,这样hover效果才不会无效*/
    }
    .nav ul li:last-child {
      width: 98px;
      height: 90%;
      position: absolute;
      z-index: 50;
      left: 5px;
      bottom: 0;
      top: 0;
      margin: auto;
      background: rgba(152,206,170,0.5);
      border-radius: 5px;
    }
  </style>
</head>
<body>
<div class="nav">
  <ul class="clearfix">
    <li><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >幼儿园</a></li>
    <li><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >小学</a></li>
    <li><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >初中</a></li>
    <li><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >高中</a></li>
    <li><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >大学</a></li>
    <li><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >社会</a></li>
    <li class="huadong" id="huaBlock"></li>
  </ul>
</div>
<script src="http://cdn.bootcss.com/jquery/2.1.0/jquery.js"></script>
<script>
  $(function(){
    $("ul li:not(:last)").hover(function(){
      $("#huaBlock").stop();  //停止正在运行的动画
      var curliWidth=$(this).outerWidth(),curleft=$(this).offset().left-$(this).parent().offset().left; //当前li的偏移量减去当前ul的偏移量就是li距离ul的距离
      // alert("curleft:"+curleft);
      $("#huaBlock").animate({"width":curliWidth,"left":curleft},500);
    },function(){
      $("#huaBlock").stop();
      $("#huaBlock").animate({"width":98,"left": 5},200);
    });
  });
</script>
</body>
</html>

使用在线HTML/CSS/JavaScript代码运行工具 http://tools.3water.com/code/HtmlJsRun测试运行效果如下:

jQuery实现的滑块滑动导航效果示例

希望本文所述对大家jQuery程序设计有所帮助。

jQuery 相关文章推荐
jQuery插件HighCharts绘制简单2D折线图效果示例【附demo源码】
Mar 21 jQuery
简述jQuery Easyui一些用法
Aug 01 jQuery
jq源码解析之绑在$,jQuery上面的方法(实例讲解)
Oct 13 jQuery
jQuery zTree 异步加载添加子节点重复问题
Nov 29 jQuery
轻松搞定jQuery+JSONP跨域请求的解决方案
Mar 06 jQuery
jQuery实现点击自身以外区域关闭弹出层功能完整示例【改进版】
Jul 31 jQuery
jQuery+vue.js实现的多选下拉列表功能示例
Jan 15 jQuery
JQuery常见节点操作实例分析
May 15 jQuery
jQuery实现的点击显示隐藏下拉菜单功能完整示例
May 17 jQuery
jQuery zTree插件快速实现目录树
Aug 16 jQuery
jQuery Datatables 动态列+跨列合并实现代码
Jan 30 jQuery
jquery实现抽奖功能
Oct 22 jQuery
jQuery实现常见的隐藏与展示列表效果示例
Jun 04 #jQuery
jQuery实现的简单获取索引功能示例
Jun 04 #jQuery
JS与jQuery实现ListBox上移,下移,左移,右移操作功能示例
May 31 #jQuery
jQuery基于Ajax实现读取XML数据功能示例
May 31 #jQuery
jQuery实现动态加载select下拉列表项功能示例
May 31 #jQuery
webpack里使用jquery.mCustomScrollbar插件的方法
May 30 #jQuery
jQuery 导航自动跟随滚动的实现代码
May 30 #jQuery
You might like
针对初学PHP者的疑难问答(2)
2006/10/09 PHP
一个比较简单的PHP 分页分组类
2009/12/10 PHP
php采用file_get_contents代替使用curl实例
2014/11/07 PHP
编写PHP脚本清除WordPress头部冗余代码的方法讲解
2016/03/01 PHP
jQuery 使用手册(二)
2009/09/23 Javascript
基于Jquery 解决Ajax请求的页面 浏览器后退前进功能,页面刷新功能实效问题
2010/12/11 Javascript
JavaScript中switch判断容易犯错的一个细节
2014/08/27 Javascript
jQuery动画效果图片轮播特效
2016/01/12 Javascript
JavaScript获取css行间样式,内连样式和外链样式的简单方法
2016/07/18 Javascript
AngularJS使用ng-inlude指令加载页面失败的原因与解决方法
2017/01/19 Javascript
解决layui中table异步数据请求不支持自定义返回数据格式的问题
2018/08/19 Javascript
实现Vue的markdown文档可以在线运行的方法示例
2018/12/11 Javascript
JS实现获取数组中最大值或最小值功能示例
2019/03/02 Javascript
Vue中遍历数组的新方法实例详解
2019/07/21 Javascript
layer.open提交子页面的form和layedit文本编辑内容的方法
2019/09/27 Javascript
Vue路由的模块自动化与统一加载实现
2020/06/05 Javascript
Vue自定义多选组件使用详解
2020/09/08 Javascript
实现vuex原理的示例
2020/10/21 Javascript
JS如何调用WebAssembly编译出来的.wasm文件
2020/11/05 Javascript
Python求两个文本文件以行为单位的交集、并集与差集的方法
2015/06/17 Python
Python-Seaborn热图绘制的实现方法
2019/07/15 Python
Python笔试面试题小结
2019/09/07 Python
Django框架ORM数据库操作实例详解
2019/11/07 Python
python 计算积分图和haar特征的实例代码
2019/11/20 Python
Pytorch 中retain_graph的用法详解
2020/01/07 Python
Python 实现黑客帝国中的字符雨的示例代码
2020/02/20 Python
python 回溯法模板详解
2020/02/26 Python
BIBLOO捷克:购买女装、男装、童装、鞋和配件
2017/01/27 全球购物
英国健身专家:WIT Fitness
2021/02/09 全球购物
医学专业本科毕业生自我鉴定
2013/12/28 职场文书
九年级语文教学反思
2014/02/04 职场文书
元旦联欢会主持词
2014/03/26 职场文书
临时租车协议范本
2014/09/23 职场文书
医疗纠纷调解协议书
2015/08/06 职场文书
小学英语教学反思范文
2016/02/15 职场文书
《坐井观天》教学反思
2016/02/18 职场文书