컴

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

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

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

기능적으로 조금만 더 추가하면 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건
+
제목 글쓴이 날짜 조회
15-05-06 조회 3,648
15-04-30 조회 3,894
15-04-30 조회 5,635
15-04-28 조회 4,060
15-04-28 조회 3,378
15-04-16 조회 4,542
15-04-13 조회 4,284
15-04-12 조회 3,845
15-04-10 조회 3,757
15-04-09 조회 4,051
15-04-09 조회 3,641
15-04-07 조회 3,271
15-04-06 조회 4,035
15-04-04 조회 4,682
15-04-04 조회 4,196
15-04-03 조회 4,357
15-04-02 조회 4,865
15-04-01 조회 6,038
15-04-01 조회 3,541
15-03-30 조회 3,405
15-03-30 조회 4,046
15-03-28 조회 4,715
15-03-27 조회 3,725
15-03-26 조회 3,446
15-03-24 조회 3,532
15-03-23 조회 3,607
15-03-23 조회 3,918
15-03-20 조회 4,036
15-03-20 조회 4,805
15-03-18 조회 3,404
15-03-18 조회 3,616
15-03-02 조회 7,975
15-02-27 조회 3,402
15-02-27 조회 3,858
15-02-25 조회 3,926
15-02-23 조회 4,235
15-02-20 조회 3,911
15-02-19 조회 3,905
15-02-12 조회 4,203
15-02-11 조회 4,704
15-02-11 조회 4,436
15-02-11 조회 5,297
15-02-10 조회 4,684
15-02-09 조회 4,827
15-02-06 조회 3,805
15-02-04 조회 4,104
15-02-04 조회 3,885
15-02-04 조회 3,568
15-02-03 조회 3,418
15-02-02 조회 3,546
15-02-02 조회 4,481
15-01-31 조회 3,579
15-01-31 조회 4,667
15-01-30 조회 6,431
15-01-30 조회 4,012
15-01-30 조회 3,964
15-01-29 조회 3,888
15-01-29 조회 3,784
15-01-29 조회 3,454
15-01-29 조회 4,741
15-01-28 조회 3,350
15-01-28 조회 3,788
15-01-26 조회 4,061
15-01-26 조회 3,995
15-01-24 조회 5,493
15-01-23 조회 3,770
15-01-23 조회 4,308
15-01-22 조회 3,620
15-01-22 조회 3,588
15-01-22 조회 4,483
15-01-20 조회 3,897
15-01-19 조회 3,705
15-01-18 조회 4,478
15-01-17 조회 3,421
15-01-16 조회 4,183
15-01-16 조회 4,065
15-01-16 조회 7,316
15-01-16 조회 3,893
15-01-15 조회 3,447
15-01-13 조회 6,097
15-01-12 조회 4,058
15-01-09 조회 3,791
15-01-09 조회 3,296
15-01-09 조회 3,579
15-01-08 조회 4,499
15-01-08 조회 6,779
15-01-07 조회 5,035
15-01-06 조회 3,629
15-01-06 조회 3,177
15-01-05 조회 4,101
15-01-05 조회 4,213
15-01-04 조회 6,310
15-01-03 조회 3,888
14-12-31 조회 5,674
14-12-30 조회 4,888
14-12-30 조회 3,519
14-12-30 조회 3,981
14-12-30 조회 5,505
14-12-27 조회 4,055
14-12-27 조회 4,144