컴

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

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

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

기능적으로 조금만 더 추가하면 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-02-12 조회 3,954
14-02-12 조회 3,014
14-02-12 조회 2,674
14-02-11 조회 3,045
14-02-11 조회 3,159
14-02-11 조회 2,936
14-02-10 조회 6,023
14-02-09 조회 2,748
14-02-08 조회 2,736
14-02-07 조회 2,733
14-02-07 조회 6,875
14-02-06 조회 2,788
14-02-06 조회 3,212
14-02-05 조회 2,990
14-02-05 조회 2,878
14-02-05 조회 3,806
14-02-05 조회 3,678
14-02-04 조회 2,811
14-02-04 조회 3,593
14-02-02 조회 3,215
14-02-01 조회 2,909
14-01-31 조회 2,787
14-01-29 조회 3,693
14-01-29 조회 3,166
14-01-29 조회 3,805
14-01-28 조회 4,842
14-01-28 조회 2,712
14-01-27 조회 2,984
14-01-27 조회 3,089
14-01-27 조회 5,590
14-01-27 조회 3,269
14-01-26 조회 3,779
14-01-25 조회 3,224
14-01-24 조회 2,771
14-01-24 조회 2,929
14-01-24 조회 3,665
14-01-22 조회 2,868
14-01-22 조회 3,032
14-01-22 조회 4,247
14-01-22 조회 3,628
14-01-22 조회 3,445
14-01-22 조회 3,429
14-01-21 조회 3,267
14-01-21 조회 3,325
14-01-20 조회 3,166
14-01-20 조회 3,573
14-01-20 조회 2,754
14-01-20 조회 3,000
14-01-19 조회 2,930
14-01-19 조회 3,500
14-01-18 조회 2,711
14-01-18 조회 3,382
14-01-16 조회 3,377
14-01-16 조회 2,598
14-01-16 조회 3,449
14-01-15 조회 4,051
14-01-15 조회 3,523
14-01-15 조회 3,739
14-01-14 조회 3,200
14-01-14 조회 2,573
14-01-13 조회 2,632
14-01-10 조회 4,903
14-01-10 조회 2,729
14-01-09 조회 2,504
14-01-09 조회 3,090
14-01-07 조회 3,122
14-01-07 조회 3,098
14-01-07 조회 2,885
14-01-06 조회 4,203
14-01-03 조회 4,511
14-01-03 조회 3,177
14-01-03 조회 2,761
14-01-03 조회 4,694
14-01-03 조회 1만
14-01-03 조회 4,406
14-01-02 조회 2,870
14-01-02 조회 3,319
13-12-27 조회 3,114
13-12-27 조회 4,229
13-12-27 조회 4,081
13-12-27 조회 2,647
13-12-27 조회 2,882
13-12-26 조회 4,030
13-12-24 조회 3,284
13-12-20 조회 2,889
13-12-20 조회 2,553
13-12-19 조회 3,327
13-12-19 조회 3,099
13-12-18 조회 3,794
13-12-18 조회 2,783
13-12-18 조회 2,805
13-12-17 조회 3,411
13-12-13 조회 2,872
13-12-12 조회 2,849
13-12-11 조회 3,318
13-12-10 조회 3,207
13-12-09 조회 3,349
13-12-09 조회 3,683
13-12-09 조회 2,858
13-12-08 조회 3,033