컴

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

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

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

기능적으로 조금만 더 추가하면 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-01 조회 3,873
14-07-31 조회 3,962
14-07-31 조회 4,823
14-07-30 조회 4,501
14-07-30 조회 4,310
14-07-30 조회 4,058
14-07-30 조회 4,135
14-07-29 조회 6,611
14-07-29 조회 4,469
14-07-28 조회 4,826
14-07-27 조회 5,068
14-07-27 조회 4,245
14-07-26 조회 4,110
14-07-26 조회 4,107
14-07-25 조회 3,554
14-07-25 조회 4,122
14-07-25 조회 4,632
14-07-23 조회 4,575
14-07-23 조회 3,752
14-07-22 조회 4,194
14-07-21 조회 3,701
14-07-21 조회 4,714
14-07-19 조회 4,073
14-07-18 조회 3,443
14-07-18 조회 5,210
14-07-17 조회 9,536
14-07-17 조회 4,166
14-07-17 조회 3,828
14-07-16 조회 4,028
14-07-16 조회 3,590
14-07-16 조회 4,123
14-07-15 조회 3,671
14-07-14 조회 6,252
14-07-13 조회 4,115
14-07-12 조회 4,516
14-07-12 조회 3,902
14-07-11 조회 5,342
14-07-10 조회 4,230
14-07-09 조회 5,632
14-07-08 조회 4,874
14-07-08 조회 5,539
14-07-08 조회 4,339
14-07-08 조회 5,506
14-07-06 조회 4,504
14-07-06 조회 3,866
14-07-05 조회 4,131
14-07-04 조회 8,510
14-07-04 조회 4,019
14-07-04 조회 3,529
14-07-04 조회 3,701
14-07-03 조회 3,848
14-07-03 조회 4,235
14-07-03 조회 4,680
14-07-02 조회 5,040
14-07-02 조회 3,928
14-07-02 조회 4,187
14-07-01 조회 3,949
14-07-01 조회 3,543
14-06-28 조회 5,190
14-06-28 조회 4,469
14-06-28 조회 6,225
14-06-27 조회 3,985
14-06-27 조회 3,841
14-06-27 조회 4,892
14-06-27 조회 5,550
14-06-26 조회 4,954
14-06-26 조회 6,118
14-06-26 조회 4,425
14-06-26 조회 6,496
14-06-26 조회 3,641
14-06-25 조회 3,926
14-06-24 조회 5,364
14-06-24 조회 3,976
14-06-24 조회 5,991
14-06-24 조회 6,133
14-06-24 조회 4,378
14-06-24 조회 5,079
14-06-20 조회 4,144
14-06-20 조회 4,445
14-06-20 조회 3,951
14-06-19 조회 5,162
14-06-18 조회 4,987
14-06-18 조회 4,117
14-06-18 조회 8,447
14-06-12 조회 5,599
14-06-12 조회 6,248
14-06-11 조회 5,142
14-06-10 조회 4,060
14-06-06 조회 5,616
14-06-05 조회 5,484
14-06-04 조회 5,079
14-05-29 조회 4,829
14-05-28 조회 3,975
14-05-27 조회 4,998
14-05-26 조회 5,512
14-05-26 조회 4,309
14-05-23 조회 5,737
14-05-21 조회 4,630
14-05-19 조회 7,585
14-05-18 조회 5,006