Home > Web Front-end > JS Tutorial > jQuery implements custom drop-down list

jQuery implements custom drop-down list

PHPz
Release: 2018-09-29 17:41:52
forward
1113 people have browsed it

This article mainly introduces the method and code sharing of using jQuery to implement a custom drop-down list. The effect is very good and the compatibility is also great. I recommend it to my friends here.

html code:

<p class="dropdownContainer">
    <p class="dropdownDefault">1</p>
    <span class="downArrow arrow"></span>
    <ul class="dropdrown-menu">
        <li><a href="#">1</a></li>
        <li><a href="#">2</a></li>
        <li><a href="#">6</a></li>
        <li><a href="#">8</a></li>
    </ul>
</p>
Copy after login

css code:

.dropdownContainer{position: relative;height: 30px;width: 100%;background: #555;}
.dropdownDefault{border:1px solid #ddd;line-height: 28px;text-indent: 0.5em;}
.dropdownContainer .downArrow{position: absolute;right: 5px;top: 9px}
.dropdrown-menu{position: absolute;top:100%;width: 100%;left: 0;background: #555;display: none;}
.dropdrown-menu li{line-height: 24px;}
.dropdrown-menu li a{display: inline-block;width: 100%;text-indent: 0.5em}
.dropdrown-menu li a:hover{background: #0078b6;font-size: 1.1em;}
.arrow{width: 0;height: 0;display: inline-block;cursor: pointer;}
.downArrow{border-left: 6px solid transparent;border-right: 6px solid transparent;border-top: 12px solid #fff;}
Copy after login

js (jquery) code:

$(".dropdownDefault,.dropdownContainer .downArrow").click(function(){
    $(this).siblings(".dropdrown-menu").show();
});
 
$(".dropdrown-menu li a").click(function(){
    $(this).parent().parent().siblings(".dropdownDefault").html($(this).html());
    $(this).parent().parent().hide();
});
Copy after login

Although the code is very simple, But isn’t the effect very cool?

The above is the entire content of this chapter. For more related tutorials, please visit jQuery Video Tutorial!

Related labels:
source:jb51.net
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