tooltip 滑鼠移動上去出現圖片或文字與title大同小異

來源:互聯網
上載者:User

標籤:style   http   color   io   os   使用   ar   java   strong   

代碼如下:


<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="jquery.qtip-1.0.0-rc3.min.js"></script>



下面舉幾個比較簡單的例子。

1、Basic text

html如下所示:

代碼如下:
<div id="content">
<a href=" ">Basic text</a>
</div>


JS代碼:

複製代碼 代碼如下:
<script type="text/javascript">
$(document).ready(function()
{
$(‘#content a[href]‘).qtip(
{
content: ‘Some basic content for the tooltip‘
});
});
</script>


效果:

2、Title attribute

html如下所示:

代碼如下:
<div id="content">
<a href=" " title="That sounds familiar...">Title attribute</a>
</div>


JS代碼:

代碼如下:
<script type="text/javascript">
$(document).ready(function()
{
$(‘#content a[href][title]‘).qtip({
content: {
text: false
},
style: ‘cream‘
});
});
</script>


效果:

3、Image

html如下所示:

代碼如下:
<div id="content">
<a href=" ">Image</a>
</div>


JS代碼:

代碼如下:
<script type="text/javascript">
$(document).ready(function()
{
$(‘#content a[href]‘).qtip({
content: ‘<img src="small.png" alt="Image" />‘
});
});
</script>


效果:

4、Corner values

html如下所示:

代碼如下:
<div id="content" style="margin-top:200px;margin-left:200px;">
<a href=" ">Corner values</a>
</div>


JS代碼:

代碼如下:
<script type="text/javascript">
var corners = ‘bottomLeft‘;
var opposites = ‘topRight‘;
$(document).ready(function()
{
$(‘#content a‘)
.hover(function()
{
$(this).html(opposites)
.qtip({
content: corners,
position: {
corner: {
tooltip: corners,
target: opposites
}
},
show: {
when: false,
ready: true
},
hide: false,
style: {
border: {
width: 5,
radius: 10
},
padding: 10,
textAlign: ‘center‘,
tip: true,
name: ‘cream‘
}
});
});
});
</script>


效果:

5、Fixed tooltips

html如下所示:

代碼如下:
<div id="content">
<img src="sample.jpg" height="200" />
</div>


JS代碼:

代碼如下:
<script type="text/javascript">
$(document).ready(function()
{
$(‘#content img‘).each(function()
{
$(this).qtip(
{
content: ‘<a href=" ">Edit</a> | <a href=" ">Delete</a>‘,
position: ‘topRight‘,
hide: {
fixed: true
},
style: {
padding: ‘5px 15px‘,
name: ‘cream‘
}
});
});
});
</script>


css代碼:

代碼如下:
<style type="text/css">
#content img{
float: left;
margin-right: 35px;
border: 2px solid #454545;
padding: 1px;
}
</style>


效果:

6、Loading html

html如下所示:

代碼如下:
<div id="content">
<a href="#" rel="sample.html">Click me</a>
</div>


JS代碼:

代碼如下:
Js代碼
<script type="text/javascript">
$(document).ready(function()
{
$(‘#content a[rel]‘).each(function()
{
$(this).qtip(
{
content: {
url: $(this).attr(‘rel‘),
title: {
text: ‘Wiki - ‘ + $(this).text(),
button: ‘Close‘
}
},
position: {
corner: {
target: ‘bottomMiddle‘,
tooltip: ‘topMiddle‘
},
adjust: {
screen: true
}
},
show: {
when: ‘click‘,
solo: true
},
hide: ‘unfocus‘,
style: {
tip: true,
border: {
width: 0,
radius: 4
},
name: ‘light‘,
width: 570
}
})
});
});
</script>


效果:

7、Modal tooltips
html如下所示:

代碼如下:
<div id="content">
<a href="#" rel="modal">Click here</a>
</div>


JS代碼:

代碼如下:
<script type="text/javascript">
$(document).ready(function()
{
$(‘a[rel="modal"]:first‘).qtip(
{
content: {
title: {
text: ‘Modal tooltips sample‘,
button: ‘Close‘
},
text: ‘hello world‘
},
position: {
target: $(document.body),
corner: ‘center‘
},
show: {
when: ‘click‘,
solo: true
},
hide: false,
style: {
width: { max: 350 },
padding: ‘14px‘,
border: {
width: 9,
radius: 9,
color: ‘#666666‘
},
name: ‘light‘
},
api: {
beforeShow: function()
{
$(‘#qtip-blanket‘).fadeIn(this.options.show.effect.length);
},
beforeHide: function()
{
$(‘#qtip-blanket‘).fadeOut(this.options.hide.effect.length);
}
}
});
$(‘<div id="qtip-blanket">‘)
.css({
position: ‘absolute‘,
top: $(document).scrollTop(),
left: 0,
height: $(document).height(),
width: ‘100%‘,
opacity: 0.7,
backgroundColor: ‘black‘,
zIndex: 5000
})
.appendTo(document.body)
.hide();
});
</script>


效果:

 

 

--------------------------------------------------------------------------------------------------------------------------------------

w3c執行個體

 

<!doctype html><html><head><meta charset="utf-8"><title>jQuery Tooltip 外掛程式</title><link rel="stylesheet" href="http://jquery.bassistance.de/tooltip/jquery.tooltip.css" /><link rel="stylesheet" href="http://jquery.bassistance.de/tooltip/demo/screen.css" /><script src="http://jquery.bassistance.de/tooltip/lib/jquery.js" type="text/javascript"></script><script src="http://jquery.bassistance.de/tooltip/lib/jquery.bgiframe.js" type="text/javascript"></script><script src="http://jquery.bassistance.de/tooltip/lib/jquery.dimensions.js" type="text/javascript"></script><script src="http://jquery.bassistance.de/tooltip/jquery.tooltip.js" type="text/javascript"></script><script src="http://jquery.bassistance.de/tooltip/demo/chili-1.7.pack.js" type="text/javascript"></script><script type="text/javascript">$(function() {$(‘#set1 *‘).tooltip();$("#foottip a").tooltip({bodyHandler: function() {return $($(this).attr("href")).html();},showURL: false});$(‘#tonus‘).tooltip({delay: 0,showURL: false,bodyHandler: function() {return $("<img/>").attr("src", this.src);}});$(‘#yahoo a‘).tooltip({track: true,delay: 0,showURL: false,showBody: " - ",fade: 250});$("select").tooltip({left: 25});$("map > area").tooltip({ positionLeft: true });$("#fancy, #fancy2").tooltip({track: true,delay: 0,showURL: false,fixPNG: true,showBody: " - ",extraClass: "pretty fancy",top: -15,left: 5});$(‘#pretty‘).tooltip({track: true,delay: 0,showURL: false,showBody: " - ",extraClass: "pretty",fixPNG: true,left: -120});$(‘#right a‘).tooltip({track: true,delay: 0,showURL: false,extraClass: "right"});$(‘#right2 a‘).tooltip({ showURL: false, positionLeft: true });$("#block").click($.tooltip.block);});</script></head><body><h1 id="banner">jQuery Tooltip 外掛程式示範</h1><div id="main"><fieldset id="set1"><legend>三個帶有預設設定的 Tooltip 的元素</legend><a title="一個帶有預設設定的 tooltip,href 顯示在標題下" href="http://google.de">連結到Google</a><br/><label title="一個帶有 title 和預設設定的標籤,沒有 href" for="text1">請輸入一些字元!</label><br/><input title="請注意,當點擊 input 元素時,tooltip 消失" type="text" value="測試" name="action" id="text1"/><h3>代碼</h3><code class="mix">$(‘#set1 *‘).tooltip();</code></fieldset><fieldset id="foottip"><legend>使用 bodyHandler 來顯示 tooltip 中的腳註</legend>一些指向 <a href="#footnote">腳註</a> 的文本。<br/><br/><br/><br/><br/><div id="footnote"><em>這裡</em>是一個實際的腳註,通過嵌套的 <strong>HTML</strong> 來完成。</div><h3>代碼</h3><code class="mix">$("#foottip a").tooltip({bodyHandler: function() {return $($(this).attr("href")).html();},showURL: false});</code></fieldset><fieldset><legend>一個帶有 tooltip 的映像</legend><img id="tonus" src="http://jquery.bassistance.de/tooltip/demo/image.png" height="80" title="沒有延遲。src 值顯示在標題下" /><h3>代碼</h3><code class="mix">$(‘#tonus‘).tooltip({delay: 0,showURL: false,bodyHandler: function() {return $("&lt;img/&gt;").attr("src", this.src);}});</code></fieldset><fieldset><legend>鎖定 tooltip</legend><button id="block">點擊按鈕鎖定/解鎖所有的 tooltip</button><h3>代碼</h3><code class="mix">$("#block").click($.tooltip.block);</code></fieldset><fieldset><legend>下面四個連結沒有延遲跟蹤和漸層,帶有額外的內容</legend><div id="yahoo"><a title="Yahoo doo - more content" href="http://yahoo.com">連結到雅虎</a><a title="Yahoo doo2 - wohooo" href="http://yahoo.com">連結到雅虎 1</a><a title="Yahoo doo3" href="http://yahoo.com">連結到雅虎 2</a><a title="Yahoo doo4 - buga!" href="http://yahoo.com">連結到雅虎 3</a></div><select><option>bgiframe test</option></select><h3>代碼</h3><code class="mix">$(‘#yahoo a‘).tooltip({track: true,delay: 0,showURL: false,showBody: " - ",fade: 250});</code></fieldset><fieldset><legend>帶有額外的 class 的 tooltip。用於在一個頁面上顯示不同的 tooltip 樣式</legend><em>請注意,當滑鼠停留在右邊視區邊界時,右邊的那個 tooltip 如何顯示一個不同的背景圖片。</em><br/><span id="fancy" title="注意 - 請注意,這裡帶有一些自訂的樣式。">一個奇特的 tooltip,帶有一些自訂的樣式。</span><span id="fancy2" title="注意 - 請注意,這裡帶有一些自訂的樣式。">一個奇特的 tooltip,帶有一些自訂的樣式。</span><p><span id="pretty" title="注意 - 請注意,這裡帶有更多自訂的樣式。">一個奇特的 tooltip,帶有陰影和一些額外的內容。</span></p><br/><br/><br/><select><option>bgiframe test</option></select><h3>代碼</h3><code class="mix">$("#fancy, #fancy2").tooltip({track: true,delay: 0,showURL: false,opacity: 1,fixPNG: true,showBody: " - ",extraClass: "pretty fancy",top: -15,left: 5});$(‘#pretty‘).tooltip({track: true,delay: 0,showURL: false,showBody: " - ",extraClass: "pretty",fixPNG: true,opacity: 0.95,left: -120});</code></fieldset><fieldset><legend>下拉框</legend><select title="帶有 tooltip 的 select"><option>1. option</option><option>2. option</option><option>3. option</option></select></fieldset><fieldset><legend>帶有 tooltip 的映像地圖</legend><img id="map" src="karte.png" width="345" height="312" border="0" usemap="#Landkarte"><map name="Landkarte">  <area shape="rect" coords="11,10,59,29"        href="http://www.koblenz.de/" alt="Koblenz" title="Koblenz">  <area shape="rect" coords="42,36,96,57"        href="http://www.wiesbaden.de/" alt="Wiesbaden" title="Wiesbaden">  <area shape="rect" coords="42,59,78,80"        href="http://www.mainz.de/" alt="Mainz" title="Mainz">  <area shape="rect" coords="100,26,152,58"        href="http://www.frankfurt.de/" alt="Frankfurt" title="Frankfurt">  <area shape="rect" coords="27,113,93,134"        href="http://www.mannheim.de/" alt="Mannheim" title="Mannheim">  <area shape="rect" coords="100,138,163,159"        href="http://www.heidelberg.de/" alt="Heidelberg" title="Heidelberg">  <area shape="rect" coords="207,77,266,101"        href="http://www.wuerzburg.de/" alt="W&uuml;rzburg" title="W&uuml;rzburg">  <area shape="rect" coords="282,62,344,85"        href="http://www.bamberg.de/" alt="Bamberg" title="Bamberg">  <area shape="rect" coords="255,132,316,150"        href="http://www.nuernberg.de/" alt="N&uuml;rnberg" title="N&uuml;rnberg">  <area shape="rect" coords="78,182,132,200"        href="http://www.karlsruhe.de/" alt="Karlsruhe" title="Karlsruhe">  <area shape="rect" coords="142,169,200,193"        href="http://www.heilbronn.de/" alt="Heilbronn" title="Heilbronn">  <area shape="rect" coords="140,209,198,230"        href="http://www.stuttgart.de/" alt="Stuttgart" title="Stuttgart">  <area shape="rect" coords="187,263,222,281"        href="http://www.ulm.de/" alt="Ulm" title="Ulm">  <area shape="rect" coords="249,278,304,297"        href="http://www.augsburg.de/" alt="Augsburg" title="Augsburg">  <area shape="poly" coords="48,311,105,248,96,210,75,205,38,234,8,310"        href="http://www.baden-aktuell.de/" alt="Baden" title="Baden"></map><h3>代碼</h3><code class="mix">$("map *").tooltip({ positionLeft: true });</code></fieldset><fieldset><legend>在視區的邊界測試重新置放</legend><p id="right">帶有固定寬度的 tooltip<br/><a title="短標題" href="http://google">連結到Google</a><br/><a title="長標題,沒有其他含義,只是一個長標題,一個很長很長很長很長很長的標題" href="http://google">連結到Google</a></p><p id="right2">帶有自動寬度的 tooltip<br/><a title="短標題" href="http://google">連結到Google</a><br/><a title="長標題,沒有其他含義,只是一個長標題,一個很長很長很長很長很長的標題" href="http://google">連結到Google</a></p><h3>代碼</h3><code class="mix">$(‘#right a‘).tooltip({track: true,delay: 0,showURL: false,extraClass: "right"});$(‘#right2 a‘).tooltip({ showURL: false, positionLeft: true });</code></fieldset></div></body></html>

tooltip 滑鼠移動上去出現圖片或文字與title大同小異

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.