컴

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

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

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

기능적으로 조금만 더 추가하면 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-03-24 조회 3,676
14-03-24 조회 3,470
14-03-23 조회 8,067
14-03-22 조회 3,365
14-03-21 조회 3,463
14-03-20 조회 5,976
14-03-19 조회 3,746
14-03-19 조회 7,465
14-03-19 조회 4,864
14-03-18 조회 5,590
14-03-18 조회 3,280
14-03-17 조회 3,375
14-03-17 조회 4,367
14-03-17 조회 3,493
14-03-17 조회 4,506
14-03-17 조회 4,483
14-03-17 조회 7,395
14-03-16 조회 3,873
14-03-16 조회 4,986
14-03-16 조회 4,226
14-03-15 조회 4,249
14-03-15 조회 4,367
14-03-15 조회 3,736
14-03-15 조회 4,469
14-03-15 조회 3,086
14-03-14 조회 6,769
14-03-14 조회 4,673
14-03-14 조회 4,484
14-03-13 조회 3,932
14-03-13 조회 9,496
14-03-13 조회 3,822
14-03-13 조회 3,544
14-03-13 조회 5,445
14-03-13 조회 4,393
14-03-13 조회 3,581
14-03-12 조회 4,094
14-03-12 조회 5,336
14-03-12 조회 4,687
14-03-12 조회 4,491
14-03-12 조회 4,920
14-03-12 조회 5,062
14-03-12 조회 6,013
14-03-12 조회 5,478
14-03-11 조회 5,728
14-03-11 조회 6,337
14-03-11 조회 6,127
14-03-11 조회 3,446
14-03-11 조회 6,925
14-03-11 조회 8,088
14-03-10 조회 3,628
14-03-08 조회 4,855
14-03-07 조회 3,968
14-03-07 조회 3,287
14-03-06 조회 3,755
14-03-06 조회 3,320
14-03-05 조회 5,463
14-03-04 조회 4,213
14-03-04 조회 3,292
14-03-04 조회 3,331
14-03-04 조회 3,787
14-03-03 조회 3,433
14-03-03 조회 3,559
14-03-02 조회 3,239
14-03-02 조회 3,289
14-02-28 조회 3,372
14-02-26 조회 3,249
14-02-26 조회 3,243
14-02-25 조회 3,401
14-02-25 조회 5,950
14-02-24 조회 3,672
14-02-24 조회 2,922
14-02-24 조회 2,964
14-02-24 조회 4,759
14-02-23 조회 3,891
14-02-20 조회 3,327
14-02-20 조회 2,984
14-02-20 조회 3,388
14-02-20 조회 2,983
14-02-18 조회 3,935
14-02-17 조회 3,387
14-02-17 조회 2,859
14-02-17 조회 3,066
14-02-17 조회 4,245
14-02-17 조회 3,889
14-02-17 조회 3,466
14-02-15 조회 2,839
14-02-14 조회 3,410
14-02-14 조회 2,808
14-02-14 조회 5,039
14-02-14 조회 3,740
14-02-14 조회 3,759
14-02-14 조회 2,999
14-02-14 조회 2,781
14-02-14 조회 5,107
14-02-14 조회 3,329
14-02-14 조회 2,816
14-02-14 조회 5,219
14-02-13 조회 2,988
14-02-13 조회 4,988
14-02-12 조회 5,700