菜鸟学堂
在线运行
源代码
<!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"> <style> .photo { width: 300px; text-align: center; } .photo .ui-widget-header { margin: 1em 0; } .map { width: 350px; height: 350px; } .ui-tooltip { max-width: 350px; } </style> <script> $(function() { $( document ).tooltip({ items: "img, [data-geo], [title]", content: function() { var element = $( this ); if ( element.is( "[data-geo]" ) ) { var text = element.text(); return "<img class='map' alt='" + text + "' src='http://maps.google.com/maps/api/staticmap?" + "zoom=11&size=350x350&maptype=terrain&sensor=false¢er=" + text + "'>"; } if ( element.is( "[title]" ) ) { return element.attr( "title" ); } if ( element.is( "img" ) ) { return element.attr( "alt" ); } } }); }); </script> </head> <body> <div class="ui-widget photo"> <div class="ui-widget-header ui-corner-all"> <h2>圣史蒂芬大教堂(St. Stephen's Cathedral)</h2> <h3><a href="http://maps.google.com/maps?q=vienna,+austria&z=11" data-geo="">奥地利维也纳(Vienna, Austria)</a></h3> </div> <a href="http://en.wikipedia.org/wiki/File:Wien_Stefansdom_DSC02656.JPG"> <img src="/wp-content/uploads/2014/03/st-stephens.jpg" alt="圣史蒂芬大教堂(St. Stephen's Cathedral)" class="ui-corner-all"> </a> </div> <div class="ui-widget photo"> <div class="ui-widget-header ui-corner-all"> <h2>塔桥(Tower Bridge)</h2> <h3><a href="http://maps.google.com/maps?q=london,+england&z=11" data-geo="">英国伦敦(London, England)</a></h3> </div> <a href="http://en.wikipedia.org/wiki/File:Tower_bridge_London_Twilight_-_November_2006.jpg"> <img src="/wp-content/uploads/2014/03/tower-bridge.jpg" alt="塔桥(Tower Bridge)" class="ui-corner-all"> </a> </div> <p>所有的图片源自 <a href="http://commons.wikimedia.org/wiki/Main_Page">Wikimedia Commons</a>,且归 <a href="http://creativecommons.org/licenses/by-sa/3.0/deed.en" title="Creative Commons Attribution-ShareAlike 3.0">CC BY-SA 3.0</a> 下版权持有人所有。</p> </body> </html>
运行结果
在线运行
菜鸟学堂 edu.jb51.net