티스토리 뷰
728x90
반응형
CSS
<style type="text/css">
.container {
position: relative;
width: 100px;
height: 23px;
}
.placeholder-label {
position: absolute;
top: 4px;
right: 40px;
pointer-events: none;
color: #888;
transition: right 0.3s, font-size 0.3s;
}
.focused {
top: 4px;
right: 20px;
font-size: 10px;
}
.blured {
top: 4px;
right: 40px;
font-size: 13px;
}
</style>
HTML
<div class="container">
<input type="number" id="krw" class="qwms-inp__box" style="width:100px;" placeholder="0" onfocus="Page.onFocus('placeholder_krw')" onblur="Page.onBlur('placeholder_krw', this)">
<label for="krw" id="placeholder_krw" class="placeholder-label">KRW</label>
</div>
Javascript
var Page = {
onBlur: function (placeholder_id, object) {
const placeholder = document.getElementById(placeholder_id);
if (object.value.trim() === '') {
placeholder.classList.remove('focused');
placeholder.classList.add('blured');
}
},
onFocus: function (placeholder_id) {
const placeholder = document.getElementById(placeholder_id);
placeholder.classList.add('focused');
placeholder.classList.remove('blured');
},
}
샘플2
<!DOCTYPE html>
<html>
<head>
<title>Label Position on Text Box Click</title>
<style type="text/css">
.container {
position: relative;
width: 220px;
height: 40px;
}
.text-box {
width: 200px;
height: 30px;
padding: 5px;
font-size: 16px;
}
.placeholder-label {
position: absolute;
top: 10px;
left: 10px;
pointer-events: none;
color: #888;
transition: top 0.3s, left 0.3s, font-size 0.3s;
}
.focused {
top: 0px;
left: 5px;
font-size: 12px;
}
.blured {
top: 10px;
left: 10px;
font-size: 16px;
}
</style>
</head>
<body>
<div class="container">
<input type="text" id="myTextBox" class="text-box">
<label for="myTextBox" class="placeholder-label">Enter your text here</label>
</div>
<script>
const textBox = document.getElementById('myTextBox');
textBox.addEventListener('blur', function () {
if (textBox.value.trim() === '') {
placeholderLabel.classList.remove('focused');
placeholderLabel.classList.add('blured');
}
});
const placeholderLabel = document.querySelector('.placeholder-label');
textBox.addEventListener('focus', function () {
placeholderLabel.classList.add('focused');
placeholderLabel.classList.remove('blured');
});
</script>
</body>
</html>
728x90
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- java 키워드 정리
- system.io
- java-개발 환경 설정하기
- jstl(java standard tag library)
- 스프링 프레임워크(spring framewordk)
- System.Diagnostics
- 스프링 프레임워크(spring framework)
- 메이븐(maven)
- 상품 등록
- 표현 언어(expression language)
- .submit()
- 람다식(lambda expression)
- In App Purchase
- jsp 오픈 소스
- nl2br
- MainActor
- REST API
- 인텔리제이(intellij)
- 스프링 시큐리티(spring security)
- 특정 문자를 기준으로 자르기
- java web-mvc
- error-java
- jstl(java standard tag library)-core
- java.sql
- 스프링 시큐리티(spring security)-http basic 인증
- 제품 등록
- 진수 변환
- await
- React
- 문자 자르기
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
글 보관함