지운아빠

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

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

우선 이 글에서, 자바스크립트를 끈 하위 브라우저에서는 활용할 수 없는 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에서 활동 중인 고수님이 댓글을 달아주시니 감개무량합니다? 하하하
^^ 완정 공감이 되면서도 저도 고민을 많이하고 실 작업시에는 너무 귀차니즘과 다른것까지 수정을 해야 하는 점 때문에 그냥 넘어가는 점을 깔끔하게 정리해주셨네요.~~~
잘봤습니다. 정말 유용하겠네요~ ㅎㅎ
이런 방법도 있네요ㅜㅜ 정말 많이 배우고 갑니다..
와우 감사합니다. 잘보고 갑니다.
댓글을 작성하시려면 로그인이 필요합니다. 로그인

프로그램

+
제목 글쓴이 날짜 조회
12년 전 조회 1,025
12년 전 조회 3,756
12년 전 조회 910
12년 전 조회 1,762
12년 전 조회 924
12년 전 조회 2,151
12년 전 조회 7,935
12년 전 조회 1,922
12년 전 조회 1,712
12년 전 조회 1,529
12년 전 조회 595
12년 전 조회 2,113
12년 전 조회 1,842
12년 전 조회 635
12년 전 조회 1,196
12년 전 조회 618
12년 전 조회 901
12년 전 조회 1,187
13년 전 조회 3,575
13년 전 조회 2,108
13년 전 조회 2,299
13년 전 조회 3,669
13년 전 조회 3,477
13년 전 조회 3,133
13년 전 조회 4,001
13년 전 조회 1,015
13년 전 조회 5,981
13년 전 조회 1,368
13년 전 조회 1,217
13년 전 조회 3,401
13년 전 조회 3,032
13년 전 조회 5,185
13년 전 조회 2,692
13년 전 조회 3,327
13년 전 조회 1,018
13년 전 조회 846
13년 전 조회 2,016
13년 전 조회 810
13년 전 조회 2,213
13년 전 조회 1,510
13년 전 조회 1,110
13년 전 조회 2,100
13년 전 조회 2,314
13년 전 조회 1,314
13년 전 조회 790
13년 전 조회 1,336
13년 전 조회 827
13년 전 조회 1,212
13년 전 조회 3,850
13년 전 조회 3,947
13년 전 조회 1,368
13년 전 조회 6,969
13년 전 조회 7,552
13년 전 조회 2,308
13년 전 조회 3,860
13년 전 조회 634
13년 전 조회 3,657
13년 전 조회 3,480
13년 전 조회 2,714
13년 전 조회 2,815
13년 전 조회 2,358
13년 전 조회 2,264
13년 전 조회 5,170
13년 전 조회 2,807
13년 전 조회 3,128
13년 전 조회 2,252
13년 전 조회 6,827
13년 전 조회 2,560
13년 전 조회 3,419
13년 전 조회 2,315
13년 전 조회 4,811
13년 전 조회 3,679
13년 전 조회 2,543
13년 전 조회 2,227
13년 전 조회 1,285
13년 전 조회 3,428
13년 전 조회 4,087
13년 전 조회 3,449
13년 전 조회 5,328
13년 전 조회 1,651
13년 전 조회 1,269
13년 전 조회 5,166
13년 전 조회 939
13년 전 조회 3,404
13년 전 조회 3,407
13년 전 조회 2,991
13년 전 조회 3,348
13년 전 조회 2,868
13년 전 조회 2,843
13년 전 조회 2,868
13년 전 조회 2,862
13년 전 조회 2,884
13년 전 조회 2,829
13년 전 조회 2,857
13년 전 조회 1,483
13년 전 조회 896
13년 전 조회 810
13년 전 조회 595
13년 전 조회 2,818
13년 전 조회 2,960
🐛 버그신고