컴

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

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

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

기능적으로 조금만 더 추가하면 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-10-25 조회 5,212
14-10-25 조회 6,406
14-10-25 조회 3,818
14-10-25 조회 3,969
14-10-24 조회 3,924
14-10-23 조회 4,538
14-10-22 조회 3,682
14-10-22 조회 4,357
14-10-22 조회 7,204
14-10-22 조회 4,910
14-10-22 조회 4,859
14-10-22 조회 9,023
14-10-19 조회 4,785
14-10-18 조회 5,754
14-10-17 조회 5,267
14-10-17 조회 4,048
14-10-17 조회 6,132
14-10-17 조회 5,524
14-10-17 조회 9,053
14-10-17 조회 6,530
14-10-17 조회 4,824
14-10-17 조회 5,146
14-10-14 조회 3,365
14-10-14 조회 4,283
14-10-13 조회 3,845
14-10-13 조회 6,527
14-10-13 조회 4,464
14-10-13 조회 4,360
14-10-13 조회 4,559
14-10-11 조회 6,728
14-10-11 조회 6,632
14-10-11 조회 6,516
14-10-10 조회 4,019
14-10-10 조회 6,475
14-10-10 조회 5,754
14-10-10 조회 6,331
14-10-10 조회 3,585
14-10-10 조회 5,505
14-10-10 조회 5,506
14-10-10 조회 5,580
14-10-10 조회 4,497
14-10-10 조회 4,992
14-10-10 조회 4,285
14-10-10 조회 4,132
14-10-08 조회 4,670
14-10-08 조회 3,784
14-10-08 조회 7,004
14-10-07 조회 6,217
14-10-07 조회 4,543
14-10-07 조회 5,568
14-10-07 조회 3,759
14-10-07 조회 4,741
14-10-07 조회 6,408
14-10-06 조회 6,764
14-10-06 조회 7,545
14-10-05 조회 3,751
14-10-04 조회 5,038
14-10-03 조회 6,353
14-10-02 조회 3,924
14-09-29 조회 4,116
14-09-29 조회 4,574
14-09-28 조회 3,898
14-09-27 조회 5,242
14-09-27 조회 4,697
14-09-26 조회 6,784
14-09-26 조회 5,217
14-09-25 조회 7,558
14-09-25 조회 4,065
14-09-25 조회 4,075
14-09-24 조회 4,871
14-09-24 조회 4,829
14-09-24 조회 4,326
14-09-24 조회 3,890
14-09-24 조회 4,509
14-09-24 조회 3,984
14-09-23 조회 4,158
14-09-23 조회 4,277
14-09-23 조회 4,058
14-09-22 조회 3,934
14-09-22 조회 4,858
14-09-22 조회 4,965
14-09-22 조회 6,183
14-09-22 조회 4,144
14-09-22 조회 3,827
14-09-22 조회 3,906
14-09-21 조회 5,842
14-09-21 조회 4,619
14-09-21 조회 4,452
14-09-21 조회 3,935
14-09-21 조회 4,494
14-09-21 조회 4,382
14-09-21 조회 4,062
14-09-20 조회 4,039
14-09-20 조회 3,945
14-09-20 조회 3,849
14-09-20 조회 4,575
14-09-20 조회 4,026
14-09-19 조회 3,936
14-09-19 조회 4,106
14-09-19 조회 4,314