jquery手风琴特效插件_jquery
程序员文章站
2022-04-16 16:13:37
...
手风琴效果是项目中使用频率较高的一种效果,原来项目一直都在用easyui的,临近年末,试着自己写了一个
/* CSS Document */
body {
margin: 0 auto;
padding: 0 auto;
font-size: 9pt;
font-family: 微软雅黑, 宋体, Arial, Helvetica, Verdana, sans-serif;
}
.accordion {
padding-left: 0px;
}
.accordion li {
border-top: 1px solid #000;
list-style-type: none;
}
.titlemenu {
width: 100%;
height: 30px;
background-color: #F2F2F2;
padding: 5px 0px;
text-align: left;
cursor: pointer;
}
.titlemenu img {
position: relative;
left: 20px;
top: 5px;
}
.titlemenu span {
display: inline-block;
position: relative;
left: 40px;
}
.submenu {
text-align: left;
width: 100%;
padding-left: 0px;
}
.submenu li {
list-style-type: none;
width: 100%;
}
.submenu li img {
position: relative;
left: 20px;
top: 5px;
}
.submenu li a {
position: relative;
left: 40px;
top: 5px;
text-decoration: none;
}
.submenu li span {
display: inline-block;
height: 30px;
padding: 5px 0px;
}
.hover {
background-color: #4A5B79;
}
(function ($) {
piano = function () {
_menu ='[{"title":"一级目录","img":"images/cog.png","submenu":[{"title":"二级目录","img":"images/monitor_window_3d.png"},{"title":"二级目录","img":"images/monitor_window_3d.png"},{"title":"二级目录","img":"images/monitor_window_3d.png"}]},{"title":"一级目录","img":"images/cog.png","submenu":[{"title":"二级目录","img":"images/monitor_window_3d.png"},{"title":"二级目录","img":"images/monitor_window_3d.png"},{"id":"4","title":"二级目录","img":"images/monitor_window_3d.png"}]}]';
return ep = {
init: function (obj) {
_menu = eval('(' + _menu + ')');
var li ="";
$.each(_menu, function (index, element) {
li += '
if(element.submenu!=null)
{
li+=' ';
}
li+=' '; ';
});
obj.append(li);
}
}
}
$.fn.accordion = function (options) {
var pia = new piano();
pia.init($(this));
return this.each(function () {
var accs = $(this).children('li');
accs.each(reset);
accs.click(onClick);
var menu_li = $(".submenu").children("li");
menu_li.each(function (index, element) {
$(this).mousemove(function (e) {
$(this).siblings().removeClass("hover");
$(this).find("a").css("color", "#fff");
$(this).siblings().find("a").css("color", "#000");
$(this).addClass("hover");
});
});
});
}
function onClick() {
$(this).siblings('li').find("ul").each(hide);
$(this).find("ul").slideDown('normal');
return false;
}
function hide() {
$(this).slideUp('normal');
}
function reset() {
$(this).find("ul").hide();
}
})(jQuery);
无标题文档
css样式
复制代码 代码如下:
/* CSS Document */
body {
margin: 0 auto;
padding: 0 auto;
font-size: 9pt;
font-family: 微软雅黑, 宋体, Arial, Helvetica, Verdana, sans-serif;
}
.accordion {
padding-left: 0px;
}
.accordion li {
border-top: 1px solid #000;
list-style-type: none;
}
.titlemenu {
width: 100%;
height: 30px;
background-color: #F2F2F2;
padding: 5px 0px;
text-align: left;
cursor: pointer;
}
.titlemenu img {
position: relative;
left: 20px;
top: 5px;
}
.titlemenu span {
display: inline-block;
position: relative;
left: 40px;
}
.submenu {
text-align: left;
width: 100%;
padding-left: 0px;
}
.submenu li {
list-style-type: none;
width: 100%;
}
.submenu li img {
position: relative;
left: 20px;
top: 5px;
}
.submenu li a {
position: relative;
left: 40px;
top: 5px;
text-decoration: none;
}
.submenu li span {
display: inline-block;
height: 30px;
padding: 5px 0px;
}
.hover {
background-color: #4A5B79;
}
自定义js
复制代码 代码如下:
(function ($) {
piano = function () {
_menu ='[{"title":"一级目录","img":"images/cog.png","submenu":[{"title":"二级目录","img":"images/monitor_window_3d.png"},{"title":"二级目录","img":"images/monitor_window_3d.png"},{"title":"二级目录","img":"images/monitor_window_3d.png"}]},{"title":"一级目录","img":"images/cog.png","submenu":[{"title":"二级目录","img":"images/monitor_window_3d.png"},{"title":"二级目录","img":"images/monitor_window_3d.png"},{"id":"4","title":"二级目录","img":"images/monitor_window_3d.png"}]}]';
return ep = {
init: function (obj) {
_menu = eval('(' + _menu + ')');
var li ="";
$.each(_menu, function (index, element) {
li += '
if(element.submenu!=null)
{
li+=' ';
}
li+='
});
obj.append(li);
}
}
}
$.fn.accordion = function (options) {
var pia = new piano();
pia.init($(this));
return this.each(function () {
var accs = $(this).children('li');
accs.each(reset);
accs.click(onClick);
var menu_li = $(".submenu").children("li");
menu_li.each(function (index, element) {
$(this).mousemove(function (e) {
$(this).siblings().removeClass("hover");
$(this).find("a").css("color", "#fff");
$(this).siblings().find("a").css("color", "#000");
$(this).addClass("hover");
});
});
});
}
function onClick() {
$(this).siblings('li').find("ul").each(hide);
$(this).find("ul").slideDown('normal');
return false;
}
function hide() {
$(this).slideUp('normal');
}
function reset() {
$(this).find("ul").hide();
}
})(jQuery);
html调用方式
复制代码 代码如下:
显示效果
以上就是本文的全部内容了,希望大家能够喜欢
推荐阅读
-
jQuery插件jquery.fileupload与artdialog分享
-
jquery文件上传插件(ajax异步上传多个文件方法)
-
Asp.net MVC中使用JQuery插件ajaxFileUpload上传文件
-
jQuery插件FusionCharts实现的3D帕累托图效果示例【附demo源码】
-
BootStrap中jQuery插件Carousel实现轮播广告效果
-
jQuery的cookie插件实现保存用户登陆信
-
基于JQuery制作可编辑的表格特效
-
jQuery插件FusionCharts实现的2D面积图效果示例【附demo源码下载】
-
jquery图片轮播插件仿支付宝2013版全屏图片幻灯片
-
Jquery插件easyUi表单验证提交(示例代码)