컴

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

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

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

기능적으로 조금만 더 추가하면 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건
+
제목 글쓴이 날짜 조회
14-08-26 조회 7,424
14-08-25 조회 4,218
14-08-23 조회 3,985
14-08-22 조회 4,472
14-08-22 조회 1.1만
14-08-22 조회 4,025
14-08-22 조회 5,286
14-08-22 조회 4,229
14-08-22 조회 4,126
14-08-21 조회 4,282
14-08-21 조회 3,840
14-08-21 조회 3,686
14-08-20 조회 4,023
14-08-20 조회 3,690
14-08-19 조회 4,486
14-08-19 조회 3,712
14-08-19 조회 4,047
14-08-19 조회 3,819
14-08-19 조회 7,567
14-08-19 조회 3,668
14-08-18 조회 3,932
14-08-18 조회 4,456
14-08-18 조회 3,836
14-08-17 조회 8,236
14-08-17 조회 6,516
14-08-17 조회 7,944
14-08-17 조회 3,740
14-08-16 조회 4,294
14-08-16 조회 4,272
14-08-16 조회 4,334
14-08-14 조회 4,083
14-08-14 조회 3,627
14-08-13 조회 6,406
14-08-13 조회 5,966
14-08-13 조회 5,357
14-08-13 조회 4,575
14-08-13 조회 4,455
14-08-13 조회 5,832
14-08-13 조회 3,747
14-08-12 조회 4,112
14-08-12 조회 5,481
14-08-12 조회 6,353
14-08-12 조회 4,228
14-08-12 조회 3,890
14-08-12 조회 4,403
14-08-11 조회 3,748
14-08-11 조회 4,427
14-08-11 조회 3,743
14-08-11 조회 4,435
14-08-11 조회 4,188
14-08-11 조회 5,261
14-08-11 조회 6,982
14-08-11 조회 6,625
14-08-11 조회 6,738
14-08-11 조회 4,647
14-08-11 조회 4,683
14-08-11 조회 5,302
14-08-08 조회 3,962
14-08-08 조회 4,603
14-08-08 조회 6,760
14-08-07 조회 5,332
14-08-07 조회 3,670
14-08-07 조회 4,372
14-08-06 조회 4,190
14-08-06 조회 3,796
14-08-06 조회 6,081
14-08-06 조회 4,635
14-08-06 조회 4,544
14-08-06 조회 4,170
14-08-06 조회 6,433
14-08-06 조회 5,710
14-08-06 조회 4,047
14-08-06 조회 6,600
14-08-06 조회 4,081
14-08-05 조회 3,642
14-08-05 조회 3,941
14-08-05 조회 3,703
14-08-05 조회 3,730
14-08-05 조회 4,068
14-08-04 조회 4,929
14-08-04 조회 4,108
14-08-04 조회 3,697
14-08-03 조회 3,563
14-08-03 조회 5,664
14-08-03 조회 5,074
14-08-03 조회 5,324
14-08-02 조회 4,585
14-08-01 조회 5,704
14-08-01 조회 6,413
14-08-01 조회 7,588
14-08-01 조회 8,854
14-08-01 조회 5,573
14-08-01 조회 4,841
14-08-01 조회 4,769
14-08-01 조회 4,157
14-08-01 조회 4,129
14-08-01 조회 4,248
14-08-01 조회 3,931
14-08-01 조회 4,835
14-08-01 조회 5,215