부트스트랩 JS 툴팁
JS 툴팁(tooltip.js)
툴팁 플러그인은 사용자가 요소 위로 마우스 포인터를 이동할 때 나타나는 작은 팝업 상자입니다.
툴팁에 대한 튜토리얼은 부트스트랩 툴팁 튜토리얼 을 읽어보세요 .
데이터-* 속성을 통해
data-toggle="tooltip"
툴팁을 활성화합니다 .
속성 은 title
도구 설명 안에 표시되어야 하는 텍스트를 지정합니다.
예시
<a href="#" data-toggle="tooltip" title="Hooray!">Hover over me</a>
자바스크립트를 통해
툴팁은 CSS 전용 플러그인이 아니므로 jQuery로 초기화해야 합니다. 지정된 요소를 선택하고 tooltip()
메서드를 호출합니다.
예시
// Select all
elements with data-toggle="tooltips" in the document
$('[data-toggle="tooltip"]').tooltip();
// Select a specified
element
$('#myTooltip').tooltip();
툴팁 옵션
옵션은 데이터 속성 또는 JavaScript를 통해 전달할 수 있습니다. 데이터 속성의 경우 data-placement=""에서와 같이 옵션 이름을 data-에 추가합니다.
Name | Type | Default | Description | Try it |
---|---|---|---|---|
animation | boolean | true |
Specifies whether to add a CSS fade transition effect when showing and hiding the tooltip
|
|
container | string, or the boolean false | false | Appends the tooltip to a specific element. Example: container: 'body' |
|
delay | number, or object | 0 | Specifies the number of milliseconds it will take to show and hide the tooltip. To specify a delay for showing and another one for hiding, use the object structure: delay: {show: 500, hide: 100} - which will take 500 ms to show the tooltip, but only 100 ms to hide it |
|
html | boolean | false | Specifies whether to accept HTML tags in the tooltip:
When set to false (default), jQuery's text() method will be used. Use this if you are worried about XSS attacks |
|
placement | string | "top" | Specifies the tooltip position. Possible values:
|
|
selector | string, or the boolean false | false | Adds the tooltip to a specified selector | |
template | string | Base HTML to use when creating the tooltip. The tooltip's title will be inserted into the element having the class .tooltip-inner and the element with the class .tooltip-arrow will become the tooltip's arrow. The outermost wrapper element should have the .tooltip class. |
||
title | string | "" | Specifies the text that should be displayed inside the tooltip | |
trigger | string | "hover focus" | Specifies how the tooltip is triggered. Possible values:
|
|
viewport | string, or object | {selector: "body", padding: 0} | Keeps the tooltip within the bounds of this element. Example: viewport: '#viewport' or {selector: '#viewport', padding: 0} |
도구 설명 방법
다음 표에는 사용 가능한 모든 도구 설명 방법이 나열되어 있습니다.
Method | Description | Try it |
---|---|---|
.tooltip(options) | Activates the tooltip with an option. See options above for valid values | |
.tooltip("show") | Shows the tooltip | |
.tooltip("hide") | Hides the tooltip | |
.tooltip("toggle") | Toggles the tooltip | |
.tooltip("destroy") | Hides and destroys the tooltip |
툴팁 이벤트
다음 표에는 사용 가능한 모든 도구 설명 이벤트가 나열되어 있습니다.
Event | Description | Try it |
---|---|---|
show.bs.tooltip | Occurs when the tooltip is about to be shown | |
shown.bs.tooltip | Occurs when the tooltip is fully shown (after CSS transitions have completed) | |
hide.bs.tooltip | Occurs when the tooltip is about to be hidden | |
hidden.bs.tooltip | Occurs when the tooltip is fully hidden (after CSS transitions have completed) |
더 많은 예
맞춤형 툴팁 디자인
CSS를 사용하여 툴팁의 모양을 사용자 정의합니다.
예시
/* Tooltip */
.test + .tooltip > .tooltip-inner {
background-color: #73AD21;
color: #FFFFFF;
border: 1px solid green;
padding: 15px;
font-size: 20px;
}
/* Tooltip on top */
.test + .tooltip.top > .tooltip-arrow {
border-top: 5px solid green;
}
/* Tooltip on bottom */
.test + .tooltip.bottom > .tooltip-arrow {
border-bottom: 5px solid blue;
}
/* Tooltip on left */
.test + .tooltip.left > .tooltip-arrow {
border-left: 5px solid red;
}
/* Tooltip on right */
.test + .tooltip.right > .tooltip-arrow {
border-right: 5px solid black;
}