지운아빠

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

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

우선 이 글에서, 자바스크립트를 끈 하위 브라우저에서는 활용할 수 없는 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,097
12년 전 조회 3,827
12년 전 조회 974
13년 전 조회 1,822
13년 전 조회 986
13년 전 조회 2,216
13년 전 조회 7,999
13년 전 조회 1,989
13년 전 조회 1,788
13년 전 조회 1,591
13년 전 조회 655
13년 전 조회 2,182
13년 전 조회 1,900
13년 전 조회 691
13년 전 조회 1,256
13년 전 조회 683
13년 전 조회 963
13년 전 조회 1,252
13년 전 조회 3,643
13년 전 조회 2,166
13년 전 조회 2,365
13년 전 조회 3,728
13년 전 조회 3,544
13년 전 조회 3,202
13년 전 조회 4,069
13년 전 조회 1,085
13년 전 조회 6,042
13년 전 조회 1,446
13년 전 조회 1,274
13년 전 조회 3,455
13년 전 조회 3,095
13년 전 조회 5,240
13년 전 조회 2,754
13년 전 조회 3,402
13년 전 조회 1,087
13년 전 조회 911
13년 전 조회 2,085
13년 전 조회 863
13년 전 조회 2,273
13년 전 조회 1,570
13년 전 조회 1,172
13년 전 조회 2,162
13년 전 조회 2,367
13년 전 조회 1,370
13년 전 조회 852
13년 전 조회 1,398
13년 전 조회 885
13년 전 조회 1,266
13년 전 조회 3,923
13년 전 조회 4,013
13년 전 조회 1,419
13년 전 조회 7,011
13년 전 조회 7,598
13년 전 조회 2,361
13년 전 조회 3,909
13년 전 조회 685
13년 전 조회 3,716
13년 전 조회 3,556
13년 전 조회 2,787
13년 전 조회 2,874
13년 전 조회 2,417
13년 전 조회 2,310
13년 전 조회 5,233
13년 전 조회 2,862
13년 전 조회 3,188
13년 전 조회 2,318
13년 전 조회 6,878
13년 전 조회 2,618
13년 전 조회 3,483
13년 전 조회 2,376
13년 전 조회 4,869
13년 전 조회 3,748
13년 전 조회 2,590
13년 전 조회 2,291
13년 전 조회 1,338
13년 전 조회 3,476
13년 전 조회 4,139
13년 전 조회 3,497
13년 전 조회 5,386
13년 전 조회 1,707
13년 전 조회 1,326
13년 전 조회 5,221
13년 전 조회 994
13년 전 조회 3,456
13년 전 조회 3,462
13년 전 조회 3,052
13년 전 조회 3,405
13년 전 조회 2,931
13년 전 조회 2,891
13년 전 조회 2,917
13년 전 조회 2,924
13년 전 조회 2,940
13년 전 조회 2,877
13년 전 조회 2,902
13년 전 조회 1,535
13년 전 조회 955
13년 전 조회 861
13년 전 조회 642
13년 전 조회 2,873
13년 전 조회 3,012
🐛 버그신고