Cluetip 是一款輕量級 jQuery Tooltip 插件,支援從標題屬性、AJAX 載入、或指定 ID 等多種來源取得提示內容,並提供豐富的樣式與觸發方式。
官方示範頁:plugins.learningjquery.com/cluetip/demo/
<script src="jquery.js"></script>
<script src="jquery.cluetip.js"></script>
<link rel="stylesheet" href="jquery.cluetip.css" />
<a class="title" href="#" title="這是標題|這是內容,支援 HTML">滑鼠移上看提示</a>
<script>
$('a.title').cluetip({ splitTitle: '|' });
</script>
<a class="basic" href="ajax.htm" rel="ajax.htm">載入 ajax.htm</a>
<script>
$('a.basic').cluetip(); // 預設抓取 rel 指定的 URL
</script>
<a class="custom-width" href="ajax3.htm" rel="ajax3.htm">自訂寬度</a>
<script>
$('a.custom-width').cluetip({ width: '200px', showTitle: false });
</script>
<h4 title="Fancy Title!" id="ajax3.htm">Hover over me</h4>
<script>
$('h4').cluetip({ attribute: 'id', hoverClass: 'highlight' });
</script>
attribute: 'id' 表示提示內容從 id 屬性指定的 URL 載入;hoverClass 為懸停時加在目標元素上的類別。
<a href="ajaxclick.htm" rel="ajax5.htm" title="active ingredients" id="clickme">點我載入</a>
<script>
$('#clickme').cluetip({ activation: 'click', width: 650 });
</script>
<a href="ajax4.htm" title="|第一行|第二行">圓角提示</a>
<script>
$('ol.rounded a:eq(0)').cluetip({
splitTitle: '|',
dropShadow: false,
cluetipClass: 'rounded', // 需搭配 CSS .rounded 定義圓角
showTitle: false
});
</script>
| 選項 | 預設 | 說明 |
|---|---|---|
| splitTitle | '' | 標題分隔字元,啟用後 title 格式為「標題|內容」 |
| showTitle | true | 是否顯示標題列 |
| width | 270 | 提示框寬度(px 或 %) |
| activation | 'hover' | 'hover' 或 'click' |
| attribute | 'rel' | 指定 AJAX 來源屬性(rel / id / href 等) |
| cluetipClass | '' | 額外 CSS 類別,方便客製化樣式 |
| dropShadow | true | 是否顯示陰影 |