컴

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

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

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

기능적으로 조금만 더 추가하면 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건
+
제목 글쓴이 날짜 조회
15-11-05 조회 2,904
15-11-05 조회 3,764
15-11-04 조회 2,863
15-11-04 조회 2,912
15-11-04 조회 2,793
15-11-04 조회 3,001
15-11-04 조회 3,426
15-11-04 조회 3,257
15-11-03 조회 3,170
15-11-03 조회 3,580
15-11-03 조회 3,123
15-11-02 조회 3,182
15-11-02 조회 2,750
15-11-02 조회 3,074
15-11-02 조회 2,812
15-11-02 조회 2,910
15-11-01 조회 3,056
15-10-31 조회 2,664
15-10-30 조회 3,388
15-10-30 조회 2,774
15-10-29 조회 3,103
15-10-29 조회 2,823
15-10-27 조회 2,934
15-10-26 조회 3,421
15-10-23 조회 2,885
15-10-23 조회 2,923
15-10-21 조회 2,685
15-10-19 조회 4,235
15-10-19 조회 3,332
15-10-18 조회 2,981
15-10-17 조회 3,047
15-10-17 조회 2,866
15-10-17 조회 2,994
15-10-15 조회 3,679
15-10-14 조회 3,561
15-10-07 조회 4,328
15-10-06 조회 3,411
15-10-05 조회 3,260
15-10-05 조회 3,657
15-10-05 조회 2,893
15-10-05 조회 2,985
15-10-05 조회 2,933
15-10-04 조회 2,774
15-10-04 조회 2,923
15-10-04 조회 3,064
15-10-03 조회 3,814
15-10-03 조회 2,904
15-10-02 조회 3,332
15-10-02 조회 3,185
15-10-02 조회 3,160
15-10-02 조회 2,860
15-10-01 조회 2,925
15-10-01 조회 2,969
15-10-01 조회 2,850
15-10-01 조회 2,809
15-10-01 조회 3,144
15-09-30 조회 2,749
15-09-30 조회 2,873
15-09-30 조회 2,955
15-09-30 조회 2,943
15-09-25 조회 3,577
15-09-25 조회 3,322
15-09-24 조회 2,885
15-09-24 조회 2,822
15-09-24 조회 3,293
15-09-23 조회 3,292
15-09-23 조회 2,747
15-09-23 조회 2,828
15-09-23 조회 2,834
15-09-23 조회 2,836
15-09-23 조회 3,035
15-09-23 조회 2,982
15-09-22 조회 5,034
15-09-21 조회 3,014
15-09-21 조회 2,770
15-09-21 조회 2,782
15-09-21 조회 2,840
15-09-18 조회 4,407
15-09-17 조회 4,008
15-09-16 조회 3,380
15-09-14 조회 3,660
15-09-14 조회 3,814
15-09-13 조회 3,850
15-09-11 조회 3,040
15-09-11 조회 2,734
15-09-09 조회 3,370
15-09-08 조회 2,818
15-09-05 조회 2,871
15-09-04 조회 2,904
15-09-02 조회 3,536
15-09-02 조회 3,293
15-09-02 조회 3,047
15-09-01 조회 3,367
15-08-31 조회 7,747
15-08-29 조회 2,986
15-08-29 조회 4,234
15-08-28 조회 3,339
15-08-28 조회 4,205
15-08-25 조회 3,836
15-08-24 조회 2,900