Superfish高亮显示当前页面的菜单项
来源:互联网 发布:网络借贷平台哪个最快 编辑:程序博客网 时间:2024/05/17 23:29
Superfish是一个不错的jQuery下拉菜单插件,被广泛用于各种网站项目,但是其一个显著不足是无法为当前页面的菜单项添加高亮显示效果,本文将介绍如何解决这个问题。
关键字:Superfish菜单高亮、Superfish高亮显示当前页面的菜单项、Superfish高亮。
superfish的使用很简单,其参数如下:
- $.fn.superfish.defaults = {
- popUpSelector: 'ul,.sf-mega', // selector within menu context to define the submenu element to be revealed
- hoverClass: 'sfHover', // the class applied to hovered list items
- pathClass: 'overideThisToUse', // the class you have applied to list items that lead to the current page
- pathLevels: 1, // the number of levels of submenus that remain open or are restored using pathClass
- delay: 800, // the delay in milliseconds that the mouse can remain outside a submenu without it closing
- animation: {opacity:'show'}, // an object equivalent to first parameter of jQuery’s .animate() method. Used to animate the submenu open
- animationOut: {opacity:'hide'}, // an object equivalent to first parameter of jQuery’s .animate() method Used to animate the submenu closed
- speed: 'normal', // speed of the opening animation. Equivalent to second parameter of jQuery’s .animate() method
- speedOut: 'fast', // speed of the closing animation. Equivalent to second parameter of jQuery’s .animate() method
- cssArrows: true, // set to false if you want to remove the CSS-based arrow triangles
- disableHI: false, // set to true to disable hoverIntent detection
- onInit: $.noop, // callback function fires once Superfish is initialised – 'this' is the containing ul
- onBeforeShow: $.noop, // callback function fires just before reveal animation begins – 'this' is the ul about to open
- onShow: $.noop, // callback function fires once reveal animation completed – 'this' is the opened ul
- onBeforeHide: $.noop, // callback function fires just before closing animation – 'this' is the ul about to close
- onHide: $.noop, // callback function fires after a submenu has closed – 'this' is the ul that just closed
- onIdle: $.noop, // callback function fires when the 'current' submenu is restored (if using pathClass functionality)
- onDestroy: $.noop // callback function fires after the 'destroy' method is called on the menu container
- };
以上参数列表及说明来自superfish官方网站:http://users.tpg.com.au/j_birch/plugins/superfish/options/
当用于独立项目的时候,就需要考虑为当前页面的菜单项目添加高亮效果
需要添加的javascript代码:
- var path = window.location.pathname.split('/');
- path = path[path.length-1];
- if (path !== undefined) {
- $(".sf-menu")
- .find("a[href$='" + path + "']") // gets all links that match the href
- .parents('li') // gets all list items that are ancestors of the link
- // .children('a') // walks down one level from all selected li's
- .addClass('current');
- }
上面的javascript代码是将预定义好的高亮效果(上例中的红色字体,带下划线)添加给li,如果想添加给a的话,去掉上面代码中第七行最前面的注释符号即可。
0 0
- Superfish高亮显示当前页面的菜单项
- 利用superfish显示到内容页并高亮显示菜单项
- 让superfish的菜单在左边显示
- JQ当前页面标签 高亮显示
- 二级导航页面+当前页面导航高亮显示
- SharePoint 2013 高亮显示当前导航菜单
- Js实现当前导航菜单高亮显示
- 可能是ThinkPHP导航高亮显示当前页面的最简便的方法
- Superfish下拉菜单模块
- SuperFish一款基于jQuery的级联下拉菜单
- 使用js高亮菜单中属于当前页,显示网页路径,
- 菜单点击高亮显示
- jQuery高亮当前选中菜单
- asp.net + CSS实现动态菜单突出显示当前页面!
- jQuery+Superfish制作下拉菜单
- jQuery+Superfish制作下拉菜单
- jQuery+Superfish制作下拉菜单
- jQuery+Superfish制作下拉菜单
- Using声明和指令的工作原理
- ITopologicalOperator接口详解
- Android中的第一个NDK的例子
- C++程序设计实践学材系列(4)——1.1 写出第一个C++程序
- undefined reference to 'pthread_create'问题解决
- Superfish高亮显示当前页面的菜单项
- spark 官方动手练习二:用spark浏览维基百科的数据
- org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class
- windows下bat批处理实现守护进程(有日志)
- EGOImageView-缓存问题
- candy crush 抽象工厂模式
- Linux经典书籍推荐(入门导读)
- 关于surfaceview构造器的理解
- 西西河超级雄文———从过去的龙年看未来的中国(连载)