源代碼
點擊運行
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>jQuery UI 工具提示框(Tooltip) - 自定義樣式</title> <link rel="stylesheet" href="//apps.bdimg.com/libs/jqueryui/1.10.4/css/jquery-ui.min.css"> <script src="//apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script> <script src="//apps.bdimg.com/libs/jqueryui/1.10.4/jquery-ui.min.js"></script> <link rel="stylesheet" href="jqueryui/style.css"> <script> $(function() { $( document ).tooltip({ position: { my: "center bottom-20", at: "center top", using: function( position, feedback ) { $( this ).css( position ); $( "<div>" ) .addClass( "arrow" ) .addClass( feedback.vertical ) .addClass( feedback.horizontal ) .appendTo( this ); } } }); }); </script> <style> .ui-tooltip, .arrow:after { background: black; border: 2px solid white; } .ui-tooltip { padding: 10px 20px; color: white; border-radius: 20px; font: bold 14px "Helvetica Neue", Sans-Serif; text-transform: uppercase; box-shadow: 0 0 7px black; } .arrow { width: 70px; height: 16px; overflow: hidden; position: absolute; left: 50%; margin-left: -35px; bottom: -16px; } .arrow.top { top: -16px; bottom: auto; } .arrow.left { left: 20%; } .arrow:after { content: ""; position: absolute; left: 20px; top: -20px; width: 25px; height: 25px; box-shadow: 6px 5px 9px -9px black; -webkit-transform: rotate(45deg); -moz-transform: rotate(45deg); -ms-transform: rotate(45deg); -o-transform: rotate(45deg); tranform: rotate(45deg); } .arrow.top:after { bottom: -20px; top: auto; } </style> </head> <body> <p><a href="#" title="部件的名稱">Tooltips</a> 可被綁定到任意的元素上。當您的鼠標懸停在元素上時,title 屬性會顯示在元素旁邊的一個小框中,就像原生的工具提示框一樣。</p> <p>但是由於它不是一個原生的工具提示框,所以它可以被定義樣式。通過 <a href="http://themeroller.com" title="ThemeRoller:jQuery UI 的主題創建應用程序">ThemeRoller</a> 創建的主題也可以相應地定義工具提示框的樣式。</p> <p>工具提示框也可以用於表單元素,來顯示每個區域中的一些額外的信息。</p> <p><label for="age">您的年齡:</label><input id="age" title="年齡僅用於統計。"></p> <p>懸停在相應的區域上查看工具提示框。</p> </body> </html>
運行結果