鼠标滑在标题上显示图片的JS代码
更新时间:2013年11月19日 16:33:17 作者:
这篇文章主要介绍了鼠标滑在标题上显示图片的JS代码,有需要的朋友可以参考一下
复制代码 代码如下:
<SCRIPT type=text/javascript src="js/jquery.tooltip.v.1.1.js"></SCRIPT>
<SCRIPT type=text/javascript src="js/jquery.tooltip.execute.js"></SCRIPT>
机型:<a href="#nogo" class="with-tooltip" title="<img src='images/plane/${air.aircrafttype}.jpg'/>" >${air.aircrafttype}</a>
jquery.tooltip.execute.js:
$(document).ready(function(){
$(".with-tooltip").simpletooltip();
});
tooltip.v.1.1.js: www.jb51.net
/**
*
* simpleTooltip jQuery plugin, by Marius ILIE
* visit for details
*
**/
(function($){ $.fn.simpletooltip = function(){
return this.each(function() {
var text = $(this).attr("title");
$(this).attr("title", "");
if(text != undefined) {
$(this).hover(function(e){
var tipX = e.pageX + 12;
var tipY = e.pageY + 12;
$(this).attr("title", "");
$("body").append("<div id='simpleTooltip' style='position: absolute; z-index: 100; display: none;'>" + text + "</div>");
if($.browser.msie) var tipWidth = $("#simpleTooltip").outerWidth(true)
else var tipWidth = $("#simpleTooltip").width()
$("#simpleTooltip").width(tipWidth);
$("#simpleTooltip").css("left", tipX).css("top", tipY).fadeIn("medium");
}, function(){
$("#simpleTooltip").remove();
$(this).attr("title", text);
});
$(this).mousemove(function(e){
var tipX = e.pageX + 12;
var tipY = e.pageY + 12;
var tipWidth = $("#simpleTooltip").outerWidth(true);
var tipHeight = $("#simpleTooltip").outerHeight(true);
if(tipX + tipWidth > $(window).scrollLeft() + $(window).width()) tipX = e.pageX - tipWidth;
if($(window).height()+$(window).scrollTop() < tipY + tipHeight) tipY = e.pageY - tipHeight;
$("#simpleTooltip").css("left", tipX).css("top", tipY).fadeIn("medium");
});
}
});
}})(jQuery);
相关文章
网页右键ie不支持event.preventDefault和event.returnValue (需要加window)
网页右键ie不支持event.preventDefault和event.returnValue (需要加window) ,需要的朋友可以参考一下2013-02-02
JavaScript在for循环中绑定事件解决事件参数不同的情况
响应一堆相似的事件,但是每个事件的参数都不同,在这种情况下就可以使用JavaScript 在for循环中绑定事件,下面有个不错的示例,大家可以参考下2014-01-01


最新评论