지운아빠

자바스크립트를 끈 로그인 폼

작은 팁이지만 혹시 비슷한 문제로 고민하시는 분 계시면 도움이 되길 바랍니다.

우선 이 글에서, 자바스크립트를 끈 하위 브라우저에서는 활용할 수 없는 placeholder.js 는 논외로 함을 밝혀드립니다.

결과물 미리보기

     
자바스크립트를 켰을 때                            자바스크립트를 껐을 때



웹 접근성 가이드라인에서는 자바스크립트만으로 기능을 이용할 수 있어서는 안된다고 명시하고 있습니다.
이제 제가 올릴 팁은 '기능'이라기보다는 '비주얼'에 가깝지만, 비약하자면 기능과 같은 맥락에 포함된다고 볼 수도 있을 것입니다.

placeholder 를 사용할 수 없는 브라우저에 대한 대안은 두가지가 있습니다.

  1. 위에서 언급한 placeholder.js 를 사용하는 방법
  2. label 의 위치를 css 로 제어하고, js 로 효과를 주는 방법
  3. input 의 background 로 제어하는 방법
다른 방법이 더 있다면 알려주세요. 꾸벅

다음 이미지는 2번의 방법으로 만든 로그인폼입니다.


회원아이디, 패스워드는 label 입니다.
position:absolute;top:~px;left:~px;블라블라블라~ 처럼 스타일을 준 것이죠.

그리고 jquery 로 인풋박스에 focus 되었을 때, 해당 인풋박스와 연결되는 label 을 일시적으로 보이지 않게 하는 방법으로 구현합니다.

html
<fieldset>
    <input type="hidden" name="url" value="<?=$outlogin_url?>">
    <label for="ol_id" id="ol_idlabel">회원아이디</label>
    <input type="text" id="ol_id" name="mb_id" maxlength="20" required title="회원아이디">
    <label for="ol_pw" id="ol_pwlabel">패스워드</label>
    <input type="password" id="ol_pw" name="mb_password" maxlength="20" required title="패스워드">
    <input type="submit" id="ol_submit" value="로그인">
    <ul>
        <li id="ol_auto">
            <input type="checkbox" id="auto_login" name="auto_login" value="1">
            <label for="auto_login" id="auto_login_label">자동로그인</label>
        </li>
        <li><a href="<?=$g4['bbs_url']?>/register.php">회원가입</a></li>
        <li><a href="<?=$g4['bbs_url']?>/password_lost.php" id="ol_password_lost">정보찾기</a></li>
    </ul>
</fieldset>

css
#ol_id{display:block;margin-bottom:3px;padding:0 5px;width:185px;height:22px;border:1px solid #d7d7d7;background:#fff;line-height:1.6em}
#ol_idlabel {z-index:2;position:absolute;top:23px;left:20px;color:#696969}
#ol_pw {padding:0 5px;width:121px;height:22px;border:1px solid #d7d7d7;background:#fff;line-height:1.6em}
#ol_pwlabel {z-index:2;position:absolute;top:50px;left:20px;color:#696969}

js
$(document).ready(function(){
    $omi = $('#ol_id'); //아이디 입력창
    $omp = $('#ol_pw'); //패스워드 입력창
    $omi_label = $('#ol_idlabel'); //아이디 레이블
    $omp_label = $('#ol_pwlabel'); //패스워드 레이블
    $omi.focus(function() { //아이디 입력창 포커스
        $omi_label.css('visibility','hidden');
    });
    $omp.focus(function() { //패스워드 입력창 포커스
        $omp_label.css('visibility','hidden');
    });
    $omi.blur(function() { //아이디 입력창 포커스 해제
        $this = $(this);
        if($this.attr('id') == "ol_mb_id" && $this.attr('value') == "") $omi_label.css('visibility','visible');
    });
    $omp.blur(function() { //패스워드 입력창 포커스 해제
        $this = $(this);
        if($this.attr('id') == "ol_mb_pw" && $this.attr('value') == "") $omp_label.css('visibility','visible');
    });
});

아이디 인풋박스에 포커스되었을 때 이미지입니다.

이 모든 작동은 자바스크립트를 사용할 수 있는 환경에서 이루어집니다.
그런데 위에서 언급한 바와 같이 우리는 자바스크립트가 꺼진 상태도 고려를 해야 합니다.

자바스크립트를 끈 상태에서 아이디를 입력해본 모습입니다.
바로 위의 이미지에서는 회원아이디라는 label 이 깔끔하게 사라졌지만 이 이미지에서는 그대로 남아 있어,
아이디 admin 과 글자가 겹치는 현상이 나타나고 있습니다.

naver 메인화면의 로그인에서도 같은 현상이 나타나는 것을 확인할 수 있습니다.

그럼 이제 자바스크립트가 꺼진 상태에서도 레이블과 인풋박스의 글자겹침(장애)없이 식별할 수 있도록 해보겠습니다.
우선 스타일 부분에서 일정 부분은 포기를 했습니다. 비슷하게 구현하는 방법이 없진 않겠지만 시간과 노력, 코드의 양이 많으므로 간단하게 아래와 같은 디자인을 적용하겠습니다.

자바스크립트가 꺼졌을 때의 로그인 화면

html 위와 같음

css
#ol_id {display:block;margin-bottom:3px;padding:0 5px;width:185px;height:22px;border:1px solid #d7d7d7;background:#fff;line-height:1.6em}
.ol_idlabel {position:absolute;top:23px;left:20px;color:#696969}
#ol_pw {display:block;margin-bottom:3px;padding:0 5px;width:185px;height:22px;border:1px solid #d7d7d7;background:#fff;line-height:1.6em}
.ol_pwlabel {position:absolute;top:50px;left:20px;color:#696969}

js
$(document).ready(function(){
    $omi = $('#ol_id');
    $omp = $('#ol_pw');
    $omp.css('display','inline-block');
    $omp.css('width',121);
    $omi_label = $('#ol_idlabel');
    $omp_label = $('#ol_pwlabel');
    $omi_label.addClass('ol_idlabel');
    $omp_label.addClass('ol_pwlabel');
    $omi.focus(function() {
        $omi_label.css('visibility','hidden');
    });
    $omp.focus(function() {
        $omp_label.css('visibility','hidden');
    });
    $omi.blur(function() {
        $this = $(this);
        if($this.attr('id') == "ol_id" && $this.attr('value') == "") $omi_label.css('visibility','visible');
    });
    $omp.blur(function() {
        $this = $(this);
        if($this.attr('id') == "ol_pw" && $this.attr('value') == "") $omp_label.css('visibility','visible');
    });
});
처음 코드와 달라진 부분은?
초록색은 처음 코드, 빨간색은 처음 코드가 바뀐 부분입니다.
파란색은 추가된 코드입니다.
css
#ol_id{display:block;margin-bottom:3px;padding:0 5px;width:185px;height:22px;border:1px solid #d7d7d7;background:#fff;line-height:1.6em}
#ol_idlabel {z-index:2;position:absolute;top:23px;left:20px;color:#696969}
.ol_idlabel {position:absolute;top:23px;left:20px;color:#696969}
#ol_pw {padding:0 5px;width:121px;height:22px;border:1px solid #d7d7d7;background:#fff;line-height:1.6em}
#ol_pw {display:block;margin-bottom:3px;padding:0 5px;width:185px;height:22px;border:1px solid #d7d7d7;background:#fff;line-height:1.6em}
#ol_pwlabel {z-index:2;position:absolute;top:50px;left:20px;color:#696969}
.ol_pwlabel {position:absolute;top:50px;left:20px;color:#696969}

js
$(document).ready(function(){
    $omi = $('#ol_id'); //아이디 입력창
    $omp = $('#ol_pw'); //패스워드 입력창
    $omp.css('display','inline-block');
    $omp.css('width',121);
    $omi_label = $('#ol_idlabel'); //아이디 레이블
    $omp_label = $('#ol_pwlabel'); //패스워드 레이블
    $omi_label.addClass('ol_idlabel');
    $omp_label.addClass('ol_pwlabel');
    $omi.focus(function() { //아이디 입력창 포커스
        $omi_label.css('visibility','hidden');
    });
    $omp.focus(function() { //패스워드 입력창 포커스
        $omp_label.css('visibility','hidden');
    });
    $omi.blur(function() { //아이디 입력창 포커스 해제
        $this = $(this);
        if($this.attr('id') == "ol_mb_id" && $this.attr('value') == "") $omi_label.css('visibility','visible');
    });
    $omp.blur(function() { //패스워드 입력창 포커스 해제
        $this = $(this);
        if($this.attr('id') == "ol_mb_pw" && $this.attr('value') == "") $omp_label.css('visibility','visible');
    });
});
이 팁의 기본은 자바스크립트를 끈 상태에서부터 퍼블리싱을 시작하여,
자바스크립트를 활용할 수 있다면 원하는 효과를 부분적으로 적용하여 완성한다는 것입니다.

코드를 처음부터 새로 짠게 아니고 있던 것을 접근성에 맞게 개편하다보니 조금 지저분하고, 정리하는 과정에서 약간의 오차가 있을 수 있습니다. ㅠㅠ
|

댓글 15개

좋아요합니다.
저밖에 없죠?
저도 좋아요 눌렀구! 깨알팁이네요 ㅋㅋㅋ 조으당!
좋아요..저도 꾹 눌렀습니다.^^
저도 좋아요 마우스가 부셔지도록 꾸욱 눌렀어요...^^
자바스크립트 없는 애는 가라........
<noscript>
즐이염~
</noscript>

http://i-swear.com/703
이거 추천.
우선 이 글에서, 자바스크립트를 끈 하위 브라우저에서는 활용할 수 없는 placeholder.js 는 논외로 함을 밝혀드립니다.

맨 위에 이렇게 써놨는데.. OTL
와우 멋진 분석과 좋은 사례인듯 합니다. ^^
악 그러고보니 이거 퍼블리싱 강좌에 올렸어야 되는 내용인데... 한 회분을... 털썩... ㅠ
CSS로 placeholder
http://jsfiddle.net/VUPwD/

<style>
.login-form {position:relative; width:300px; margin-left:1em;padding-top:1em; border:1px solid gold; }

input[type=text] {margin-bottom:1em}
input[type=text] + label {position:absolute; left:4px; cursor:text; color:#999}
input[type=text]:focus + label {visibility:hidden}
</style>

<div class="login-form">
<input type="text" name="id" id="userID" />
<label for="userID">ID</label>
<br />
<input type="text" name="pwd" id="userPWD" />
<label for="userPWD">Password</label>
</div>

input:focus 익스7이하는 바보라서 'ㅅ';
JS를 살짝 넣어주면 되지만 JS를 끈 환경이 제목이니 생략합니다 ;p
ie6까지 고려한 환경입니다. ㅠㅠ
암튼 좋은 팁이네요. 유용하겠습니다. SIR에서 활동 중인 고수님이 댓글을 달아주시니 감개무량합니다? 하하하
^^ 완정 공감이 되면서도 저도 고민을 많이하고 실 작업시에는 너무 귀차니즘과 다른것까지 수정을 해야 하는 점 때문에 그냥 넘어가는 점을 깔끔하게 정리해주셨네요.~~~
잘봤습니다. 정말 유용하겠네요~ ㅎㅎ
이런 방법도 있네요ㅜㅜ 정말 많이 배우고 갑니다..
와우 감사합니다. 잘보고 갑니다.
댓글을 작성하시려면 로그인이 필요합니다. 로그인

프로그램

태그 필터 (최대 3개) 전체 개발자 소스 기타 mysql 팁자료실 javascript php linux flash 정규표현식 jquery node.js mobile 웹서버 os 프로그램 강좌 썸네일 이미지관련 도로명주소 그누보드5 기획자 견적서 계약서 기획서 마케팅 제안서 seo 통계 서식 통계자료 퍼블리셔 html css 반응형 웹접근성 퍼블리싱 표준화 반응형웹 홈페이지기초 부트스트랩 angularjs 포럼 스크린리더 센스리더 개발자톡 개발자팁 퍼블리셔톡 퍼블리셔팁 기획자톡 기획자팁 프로그램강좌 퍼블리싱강좌
+
제목 글쓴이 날짜 조회
12년 전 조회 1,068
12년 전 조회 3,796
12년 전 조회 945
13년 전 조회 1,792
13년 전 조회 961
13년 전 조회 2,184
13년 전 조회 7,969
13년 전 조회 1,956
13년 전 조회 1,751
13년 전 조회 1,567
13년 전 조회 626
13년 전 조회 2,145
13년 전 조회 1,874
13년 전 조회 661
13년 전 조회 1,229
13년 전 조회 643
13년 전 조회 933
13년 전 조회 1,221
13년 전 조회 3,608
13년 전 조회 2,140
13년 전 조회 2,329
13년 전 조회 3,697
13년 전 조회 3,510
13년 전 조회 3,169
13년 전 조회 4,039
13년 전 조회 1,051
13년 전 조회 6,014
13년 전 조회 1,405
13년 전 조회 1,245
13년 전 조회 3,430
13년 전 조회 3,061
13년 전 조회 5,216
13년 전 조회 2,720
13년 전 조회 3,366
13년 전 조회 1,056
13년 전 조회 880
13년 전 조회 2,049
13년 전 조회 839
13년 전 조회 2,241
13년 전 조회 1,542
13년 전 조회 1,147
13년 전 조회 2,134
13년 전 조회 2,345
13년 전 조회 1,342
13년 전 조회 823
13년 전 조회 1,371
13년 전 조회 857
13년 전 조회 1,244
13년 전 조회 3,886
13년 전 조회 3,979
13년 전 조회 1,394
13년 전 조회 6,986
13년 전 조회 7,577
13년 전 조회 2,337
13년 전 조회 3,887
13년 전 조회 659
13년 전 조회 3,693
13년 전 조회 3,516
13년 전 조회 2,752
13년 전 조회 2,851
13년 전 조회 2,383
13년 전 조회 2,277
13년 전 조회 5,200
13년 전 조회 2,843
13년 전 조회 3,158
13년 전 조회 2,284
13년 전 조회 6,855
13년 전 조회 2,592
13년 전 조회 3,454
13년 전 조회 2,349
13년 전 조회 4,837
13년 전 조회 3,711
13년 전 조회 2,568
13년 전 조회 2,261
13년 전 조회 1,312
13년 전 조회 3,457
13년 전 조회 4,116
13년 전 조회 3,477
13년 전 조회 5,358
13년 전 조회 1,681
13년 전 조회 1,299
13년 전 조회 5,203
13년 전 조회 968
13년 전 조회 3,433
13년 전 조회 3,437
13년 전 조회 3,019
13년 전 조회 3,379
13년 전 조회 2,897
13년 전 조회 2,870
13년 전 조회 2,894
13년 전 조회 2,892
13년 전 조회 2,912
13년 전 조회 2,862
13년 전 조회 2,884
13년 전 조회 1,513
13년 전 조회 930
13년 전 조회 837
13년 전 조회 621
13년 전 조회 2,844
13년 전 조회 2,989
🐛 버그신고