지운아빠

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

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

우선 이 글에서, 자바스크립트를 끈 하위 브라우저에서는 활용할 수 없는 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,076
12년 전 조회 3,800
12년 전 조회 951
13년 전 조회 1,798
13년 전 조회 969
13년 전 조회 2,192
13년 전 조회 7,975
13년 전 조회 1,963
13년 전 조회 1,764
13년 전 조회 1,572
13년 전 조회 633
13년 전 조회 2,155
13년 전 조회 1,882
13년 전 조회 666
13년 전 조회 1,240
13년 전 조회 657
13년 전 조회 939
13년 전 조회 1,230
13년 전 조회 3,617
13년 전 조회 2,150
13년 전 조회 2,337
13년 전 조회 3,705
13년 전 조회 3,520
13년 전 조회 3,180
13년 전 조회 4,047
13년 전 조회 1,059
13년 전 조회 6,020
13년 전 조회 1,412
13년 전 조회 1,255
13년 전 조회 3,435
13년 전 조회 3,070
13년 전 조회 5,223
13년 전 조회 2,729
13년 전 조회 3,373
13년 전 조회 1,063
13년 전 조회 888
13년 전 조회 2,054
13년 전 조회 842
13년 전 조회 2,248
13년 전 조회 1,545
13년 전 조회 1,154
13년 전 조회 2,139
13년 전 조회 2,351
13년 전 조회 1,347
13년 전 조회 833
13년 전 조회 1,376
13년 전 조회 866
13년 전 조회 1,248
13년 전 조회 3,893
13년 전 조회 3,984
13년 전 조회 1,403
13년 전 조회 6,994
13년 전 조회 7,582
13년 전 조회 2,343
13년 전 조회 3,892
13년 전 조회 663
13년 전 조회 3,700
13년 전 조회 3,528
13년 전 조회 2,763
13년 전 조회 2,855
13년 전 조회 2,390
13년 전 조회 2,285
13년 전 조회 5,206
13년 전 조회 2,845
13년 전 조회 3,165
13년 전 조회 2,293
13년 전 조회 6,860
13년 전 조회 2,596
13년 전 조회 3,460
13년 전 조회 2,354
13년 전 조회 4,844
13년 전 조회 3,724
13년 전 조회 2,578
13년 전 조회 2,269
13년 전 조회 1,318
13년 전 조회 3,461
13년 전 조회 4,122
13년 전 조회 3,483
13년 전 조회 5,363
13년 전 조회 1,685
13년 전 조회 1,307
13년 전 조회 5,208
13년 전 조회 973
13년 전 조회 3,435
13년 전 조회 3,443
13년 전 조회 3,025
13년 전 조회 3,383
13년 전 조회 2,905
13년 전 조회 2,872
13년 전 조회 2,898
13년 전 조회 2,900
13년 전 조회 2,918
13년 전 조회 2,866
13년 전 조회 2,886
13년 전 조회 1,518
13년 전 조회 935
13년 전 조회 841
13년 전 조회 623
13년 전 조회 2,852
13년 전 조회 2,991
🐛 버그신고