Home > Web Front-end > JS Tutorial > jquery accordion special effects plug-in_jquery

jquery accordion special effects plug-in_jquery

WBOY
Release: 2016-05-16 16:15:46
Original
1026 people have browsed it

The accordion effect is a frequently used effect in the project. It turns out that the project has been using easyui. Near the end of the year, I tried to write one myself

css style

Copy code The code is as follows:

/* CSS Document */
body {
margin: 0 auto;
Padding: 0 auto;
font-size: 9pt;
Font-family: Microsoft Yahei, 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;
}

Custom js

Copy code The code is as follows:

(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 += '
  • ' + element.title + '
    ';
                        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调用方式

    复制代码 代码如下:





    Untitled Document












    Display effect

    The above is the entire content of this article, I hope you all like it

    Related labels:
    source:php.cn
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template