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实现字体颜色渐变效果的方法
Mar 29 jQuery
jQuery日期范围选择器附源码下载
May 23 jQuery
jQuery实现动态删除LI的方法
May 30 jQuery
使用jQuery实现两个div中按钮互换位置的实例代码
Sep 21 jQuery
jQuery使用zTree插件实现可拖拽的树示例
Sep 23 jQuery
jQuery实现的淡入淡出与滑入滑出效果示例
Apr 18 jQuery
jQuery+PHP实现上传裁剪图片
Jun 29 jQuery
jQuery-ui插件sortable实现自由拖动排序
Dec 01 jQuery
jquery无缝图片轮播组件封装
Nov 25 jQuery
jQuery实现简单的Ajax调用功能示例
Feb 15 jQuery
js判断复选框是否选中的方法示例【基于jQuery】
Oct 10 jQuery
IDEA配置jQuery, $符号不再显示黄色波浪线的问题
Oct 09 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的中问验证码
2006/11/25 PHP
PHP可变函数的使用详解
2013/06/14 PHP
PHP网页游戏学习之Xnova(ogame)源码解读(八)
2014/06/23 PHP
ThinkPHP内置jsonRPC的缺陷分析
2014/12/18 PHP
PHP时间类完整实例(非常实用)
2015/12/25 PHP
php实现留言板功能
2017/03/05 PHP
Laravel 修改验证异常的响应格式实例代码详解
2020/05/25 PHP
基于jquery的代码显示区域自动拉长效果
2011/12/07 Javascript
基于mootools插件实现遮罩层新手引导
2012/05/24 Javascript
jquery.messager.js插件导致页面抖动的解决方法
2013/07/14 Javascript
JSON中双引号的轮回使用过程中一定要小心
2014/03/05 Javascript
JavaScript实现翻页功能(附效果图)
2017/02/16 Javascript
详解vue 数据传递的方法
2018/04/19 Javascript
Vue路由钩子之afterEach beforeEach的区别详解
2018/07/15 Javascript
JavaScript实现单图片上传并预览功能
2019/09/30 Javascript
webpack3升级到webpack4遇到问题总结
2019/09/30 Javascript
Layui数据表格之单元格编辑方式
2019/10/26 Javascript
微信小程序自定义纯净模态框(弹出框)的实例代码
2020/03/09 Javascript
详解微信小程序入门从这里出发(登录注册、开发工具、文件及结构介绍)
2020/07/21 Javascript
[00:20]TI9不朽观赛名额抽取
2019/08/05 DOTA
[01:23]2019完美世界全国高校联赛(春季赛)合肥全国总决赛
2019/06/10 DOTA
Python socket.error: [Errno 98] Address already in use的原因和解决方法
2014/08/25 Python
在Python中操作时间之tzset()方法的使用教程
2015/05/22 Python
简单解决Python文件中文编码问题
2015/11/22 Python
pip install urllib2不能安装的解决方法
2018/06/12 Python
Flask实现跨域请求的处理方法
2018/09/27 Python
django框架使用views.py的函数对表进行增删改查内容操作详解【models.py中表的创建、views.py中函数的使用,基于对象的跨表查询】
2019/12/12 Python
django中url映射规则和服务端响应顺序的实现
2020/04/02 Python
国际象棋商店:The Chess Store
2018/07/09 全球购物
秦兵马俑导游词
2015/02/02 职场文书
网络管理员岗位职责
2015/02/12 职场文书
详解Python中的进程和线程
2021/06/23 Python
python模块与C和C++动态库相互调用实现过程示例
2021/11/02 Python
分享提高 Python 代码的可读性的技巧
2022/03/03 Python
Python万能模板案例之matplotlib绘制直方图的基本配置
2022/04/13 Python
element tree树形组件回显数据问题解决
2022/08/14 Javascript