컴

레이어를 이용한 셀렉트 박스

· 2014-05-09 (금) 19:20:40 · 5028
아래 소스는 제가 퍼블리싱 하면서 만들었던 레이어 셀렉트 박스 소스인데요.

제이쿼리를 이용해서 아주 간단하게 만든것이에요.

기능적으로 조금만 더 추가하면 select tag와 동일하게 사용할 수 있을 거라
생각해요.

제이쿼리와 css를 좀 아시면 금방 해석 가능할 것에요.

$(document).ready(function() {
    ////////////////////////////////////////////////////////////////////////////////////
    //javascript:location.href='#'     <====  # 부분에 url을 넣는다.
    ////////////////////////////////////////////////////////////////////////////////////
    var selecttag = "\
            <div id='choicevalue'><img src=\"/images/engicon.png\" alt=\"ENG\" /></div>\
            <dl>\
                <dd onClick=\"javascript:location.href='#'\"><img src=\"/images/engicon.png\" alt=\"ENG\" width=80 height=20/></dd>\
                <dd onClick=\"javascript:location.href='#'\"><img src=\"/images/koricon.png\" alt=\"KOR\" width=80 height=20 /></dd>\
            </dl>\
    ";
    // GNB
    $(".gnb").append($("<li class=\"end\" id=\"selectmenu\">"+selecttag+"</li>"));    //<=== 이부분에 셀렉트박스 추가



    //////////////////////////////////////////////////////////////////////////////////////////////
    //레이어 셀렉트박스
    //////////////////////////////////////////////////////////////////////////////////////////////
        var defaultheight = 24;
        var defaultwidth = 80;
        var maxheight = defaultheight;
        var top = defaultheight + 4;

        $('#selectmenu').css({'padding':'2px 0','cursor':'pointer','height':defaultheight+'px','width':defaultwidth+'px','color':'#d7d7d7','position':'relative','z-index':'1000'});
        function ShowSelect(){
            $('#choicevalue').css({'clear':'both','padding':'2px 0','height':defaultheight+'px','width':defaultwidth+'px'});        
            
            var ddcnt = $('#selectmenu').children("dl").children("dd").length;
            maxheight = defaultheight * ddcnt;
            $('#selectmenu').children("dl").css({"clear":"both","position":"absolute","left":"0px","top":top+"px","z-index":"10000","height":maxheight+"px","width":defaultwidth+"px",'border':'1px solid #fff','background':'#6d656a'});
            $('#selectmenu').children("dl").children("dd").css({"clear":"both","height":defaultheight+"px","width":defaultwidth+"px"},{'padding':'2px 0px'});
            $('#selectmenu').css({"height":(maxheight+defaultheight+10)+"px"});
        }

        function HideSelect(){
            $('#selectmenu').animate({'height':defaultheight+'px'});    
        }
        $('#selectmenu').mouseenter(function(){
            ShowSelect();
        });

        $("#selectmenu").children("dl").children("dd").click(function(){
            $('#choicevalue').html($(this).html());
            HideSelect();
        });
        $('#selectmenu').mouseleave(function(){
            HideSelect();
        });

        ShowSelect();

        setTimeout(function(){
            HideSelect();
        },2000);
    //////////////////////////////////////////////////////////////////////////////////////////////
});
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

8,187건
+
제목 글쓴이 날짜 조회
13-12-07 조회 3,139
13-12-06 조회 2,654
13-12-06 조회 3,202
13-12-06 조회 2,774
13-12-06 조회 2,990
13-12-06 조회 2,679
13-12-06 조회 3,413
13-12-06 조회 3,743
13-12-06 조회 2,763
13-12-06 조회 2,719
13-12-06 조회 3,806
13-12-05 조회 2,753
13-12-05 조회 3,347
13-12-05 조회 3,206
13-12-05 조회 3,615
13-12-05 조회 3,526
13-12-04 조회 8,338
13-12-03 조회 3,490
13-12-02 조회 2,777
13-12-02 조회 2,629
13-11-30 조회 2,566
13-11-29 조회 2,819
13-11-28 조회 3,038
13-11-27 조회 3,631
13-11-27 조회 3,019
13-11-27 조회 3,402
13-11-27 조회 2,553
13-11-27 조회 2,727
13-11-27 조회 4,770
13-11-26 조회 4,022
13-11-25 조회 3,517
13-11-25 조회 5,325
13-11-23 조회 2,700
13-11-23 조회 4,798
13-11-23 조회 4,352
13-11-23 조회 4,114
13-11-23 조회 4,056
13-11-22 조회 3,069
13-11-22 조회 3,746
13-11-22 조회 3,595
13-11-22 조회 3,146
13-11-22 조회 5,563
13-11-21 조회 2,797
13-11-21 조회 3,287
13-11-20 조회 3,656
13-11-19 조회 4,084
13-11-19 조회 3,089
13-11-19 조회 3,720
13-11-19 조회 3,066
13-11-19 조회 4,831
13-11-18 조회 3,109
13-11-18 조회 2,937
13-11-18 조회 3,251
13-11-18 조회 4,992
13-11-18 조회 4,392
13-11-18 조회 6,853
13-11-18 조회 4,078
13-11-18 조회 4,495
13-11-18 조회 3,862
13-11-18 조회 3,922
13-11-18 조회 3,186
13-11-16 조회 3,215
13-11-15 조회 4,454
13-11-15 조회 3,232
13-11-14 조회 2,982
13-11-14 조회 3,744
13-11-14 조회 4,105
13-11-13 조회 3,220
13-11-13 조회 3,267
13-11-13 조회 3,444
13-11-13 조회 4,323
13-11-13 조회 3,161
13-11-12 조회 3,480
13-11-12 조회 5,696
13-11-07 조회 3,213
13-11-07 조회 3,183
13-11-06 조회 3,137
13-11-05 조회 3,855
13-11-05 조회 3,627
13-11-05 조회 6,664
13-11-05 조회 3,602
13-11-04 조회 3,204
13-11-04 조회 3,222
13-11-04 조회 3,003
13-11-02 조회 3,669
13-11-02 조회 3,304
13-11-01 조회 3,558
13-11-01 조회 2,934
13-11-01 조회 3,071
13-10-31 조회 3,140
13-10-31 조회 3,531
13-10-31 조회 3,930
13-10-31 조회 3,118
13-10-30 조회 3,423
13-10-30 조회 7,694
13-10-30 조회 5,526
13-10-30 조회 3,392
13-10-29 조회 3,226
13-10-29 조회 4,393
13-10-29 조회 3,657