컴

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

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

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

기능적으로 조금만 더 추가하면 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-12-27 조회 5,086
14-12-26 조회 4,744
14-12-25 조회 3,536
14-12-24 조회 3,739
14-12-24 조회 6,187
14-12-23 조회 4,089
14-12-23 조회 4,328
14-12-20 조회 3,723
14-12-20 조회 3,443
14-12-20 조회 3,587
14-12-19 조회 4,003
14-12-18 조회 5,545
14-12-18 조회 3,838
14-12-17 조회 4,376
14-12-16 조회 3,852
14-12-16 조회 3,647
14-12-15 조회 6,965
14-12-15 조회 3,790
14-12-14 조회 3,946
14-12-13 조회 3,547
14-12-12 조회 3,918
14-12-12 조회 3,540
14-12-12 조회 3,224
14-12-11 조회 3,149
14-12-11 조회 3,725
14-12-10 조회 3,715
14-12-10 조회 3,701
14-12-10 조회 3,763
14-12-09 조회 3,339
14-12-09 조회 3,458
14-12-08 조회 6,326
14-12-08 조회 4,273
14-12-07 조회 3,043
14-12-07 조회 3,524
14-12-07 조회 3,378
14-12-05 조회 5,056
14-12-05 조회 3,305
14-12-05 조회 3,456
14-12-04 조회 3,169
14-12-03 조회 3,665
14-12-03 조회 3,327
14-12-02 조회 3,558
14-12-02 조회 4,382
14-12-02 조회 3,131
14-12-01 조회 3,116
14-12-01 조회 4,354
14-11-29 조회 4,008
14-11-28 조회 3,958
14-11-27 조회 3,337
14-11-27 조회 4,069
14-11-27 조회 3,608
14-11-26 조회 3,464
14-11-26 조회 3,767
14-11-26 조회 3,867
14-11-25 조회 3,977
14-11-25 조회 3,864
14-11-25 조회 6,765
14-11-24 조회 5,543
14-11-24 조회 3,867
14-11-21 조회 4,202
14-11-20 조회 7,935
14-11-20 조회 4,576
14-11-19 조회 4,016
14-11-18 조회 3,558
14-11-18 조회 4,186
14-11-17 조회 4,114
14-11-16 조회 3,900
14-11-13 조회 3,204
14-11-13 조회 3,511
14-11-13 조회 3,435
14-11-12 조회 3,691
14-11-12 조회 4,171
14-11-12 조회 4,422
14-11-11 조회 3,342
14-11-11 조회 4,073
14-11-09 조회 3,839
14-11-08 조회 3,648
14-11-07 조회 7,784
14-11-06 조회 7,321
14-11-06 조회 3,763
14-11-06 조회 7,249
14-11-05 조회 6,952
14-11-05 조회 7,247
14-11-05 조회 8,102
14-11-04 조회 7,772
14-11-04 조회 7,210
14-11-04 조회 3,548
14-11-03 조회 8,524
14-11-03 조회 4,342
14-10-31 조회 3,891
14-10-31 조회 5,930
14-10-30 조회 3,764
14-10-30 조회 5,837
14-10-30 조회 5,256
14-10-28 조회 4,191
14-10-27 조회 4,365
14-10-27 조회 3,730
14-10-25 조회 5,174
14-10-25 조회 3,765
14-10-25 조회 8,432