지운아빠

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

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

우선 이 글에서, 자바스크립트를 끈 하위 브라우저에서는 활용할 수 없는 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,041
12년 전 조회 3,771
12년 전 조회 927
12년 전 조회 1,775
12년 전 조회 941
12년 전 조회 2,167
12년 전 조회 7,956
12년 전 조회 1,938
12년 전 조회 1,728
12년 전 조회 1,547
12년 전 조회 609
12년 전 조회 2,128
12년 전 조회 1,858
13년 전 조회 647
13년 전 조회 1,211
13년 전 조회 631
13년 전 조회 920
13년 전 조회 1,206
13년 전 조회 3,594
13년 전 조회 2,128
13년 전 조회 2,313
13년 전 조회 3,686
13년 전 조회 3,492
13년 전 조회 3,148
13년 전 조회 4,021
13년 전 조회 1,035
13년 전 조회 5,999
13년 전 조회 1,384
13년 전 조회 1,231
13년 전 조회 3,419
13년 전 조회 3,048
13년 전 조회 5,201
13년 전 조회 2,708
13년 전 조회 3,346
13년 전 조회 1,036
13년 전 조회 866
13년 전 조회 2,035
13년 전 조회 826
13년 전 조회 2,229
13년 전 조회 1,528
13년 전 조회 1,128
13년 전 조회 2,119
13년 전 조회 2,328
13년 전 조회 1,331
13년 전 조회 807
13년 전 조회 1,351
13년 전 조회 842
13년 전 조회 1,229
13년 전 조회 3,868
13년 전 조회 3,967
13년 전 조회 1,383
13년 전 조회 6,976
13년 전 조회 7,565
13년 전 조회 2,324
13년 전 조회 3,876
13년 전 조회 650
13년 전 조회 3,674
13년 전 조회 3,498
13년 전 조회 2,731
13년 전 조회 2,836
13년 전 조회 2,372
13년 전 조회 2,271
13년 전 조회 5,185
13년 전 조회 2,823
13년 전 조회 3,144
13년 전 조회 2,269
13년 전 조회 6,840
13년 전 조회 2,578
13년 전 조회 3,434
13년 전 조회 2,332
13년 전 조회 4,827
13년 전 조회 3,697
13년 전 조회 2,559
13년 전 조회 2,245
13년 전 조회 1,299
13년 전 조회 3,443
13년 전 조회 4,101
13년 전 조회 3,465
13년 전 조회 5,345
13년 전 조회 1,665
13년 전 조회 1,287
13년 전 조회 5,186
13년 전 조회 955
13년 전 조회 3,419
13년 전 조회 3,423
13년 전 조회 3,008
13년 전 조회 3,363
13년 전 조회 2,882
13년 전 조회 2,859
13년 전 조회 2,882
13년 전 조회 2,877
13년 전 조회 2,895
13년 전 조회 2,847
13년 전 조회 2,871
13년 전 조회 1,498
13년 전 조회 913
13년 전 조회 823
13년 전 조회 606
13년 전 조회 2,833
13년 전 조회 2,973
🐛 버그신고