컴

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

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

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

기능적으로 조금만 더 추가하면 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건
+
제목 글쓴이 날짜 조회
13-08-07 조회 3,342
13-08-06 조회 3,295
13-08-06 조회 4,331
13-08-05 조회 4,746
13-08-02 조회 3,583
13-08-01 조회 3,390
13-08-01 조회 4,098
13-07-30 조회 4,137
13-07-29 조회 3,298
13-07-29 조회 3,994
13-07-27 조회 4,241
13-07-26 조회 3,476
13-07-25 조회 4,065
13-07-25 조회 6,792
13-07-25 조회 4,200
13-07-24 조회 3,870
13-07-24 조회 3,615
13-07-24 조회 4,022
13-07-23 조회 4,477
13-07-23 조회 7,450
13-07-23 조회 8,567
13-07-23 조회 3,620
13-07-23 조회 5,243
13-07-23 조회 9,845
13-07-23 조회 5,479
13-07-23 조회 1.2만
13-07-19 조회 3,312
13-07-18 조회 3,434
13-07-16 조회 4,259
13-07-15 조회 4,614
13-07-15 조회 4,064
13-07-14 조회 4,745
13-07-14 조회 5,123
13-07-14 조회 6,077
13-07-14 조회 5,367
13-07-14 조회 5,516
13-07-14 조회 5,483
13-07-14 조회 4,788
13-07-14 조회 4,379
13-07-14 조회 4,239
13-07-14 조회 4,290
13-07-14 조회 5,034
13-07-14 조회 4,738
13-07-14 조회 4,447
13-07-14 조회 5,498
13-07-14 조회 5,404
13-07-14 조회 5,179
13-07-14 조회 4,890
13-07-14 조회 5,584
13-07-13 조회 3,846
13-07-12 조회 3,689
13-07-12 조회 3,358
13-07-12 조회 3,641
13-07-11 조회 4,210
13-07-11 조회 5,186
13-07-11 조회 5,613
13-07-11 조회 4,558
13-07-11 조회 4,244
13-07-11 조회 4,035
13-07-11 조회 1.3만
13-07-10 조회 3,787
13-07-10 조회 4,806
13-07-09 조회 4,248
13-07-09 조회 4,821
13-07-09 조회 5,087
13-07-08 조회 4,270
13-07-08 조회 4,798
13-07-07 조회 5,549
13-07-05 조회 4,362
13-07-04 조회 4,415
13-07-04 조회 4,356
13-07-04 조회 1.1만
13-07-04 조회 4,450
13-07-04 조회 4,266
13-07-04 조회 5,068
13-07-04 조회 4,138
13-07-04 조회 4,583
13-07-04 조회 4,202
13-07-04 조회 4,316
13-07-03 조회 6,041
13-07-01 조회 1.4만
13-07-01 조회 5,864
13-07-01 조회 5,943
13-07-01 조회 4,030
13-07-01 조회 5,536
13-07-01 조회 3,900
13-07-01 조회 4,819
13-07-01 조회 3,865
13-07-01 조회 4,655
13-07-01 조회 4,304
13-07-01 조회 4,723
13-07-01 조회 6,921
13-06-28 조회 5,151
13-06-28 조회 4,057
13-06-24 조회 8,625
13-06-24 조회 4,502
13-06-23 조회 4,495
13-06-21 조회 6,461
13-06-20 조회 4,768
13-06-19 조회 8,341