这应该没有那么复杂:
我正在使用Easiest Tooltip and Image Preview Using jQuery
我正在尝试使用此example
如何禁用原始图片上的点击事件,我只希望显示工具提示(我不想允许点击图片)
如何才能做到这一点?
谢谢!
这是当前样式:
<style>
#preview{
position:absolute;
border:1px solid #ccc;
background:#333;
padding:5px;
display:none;
color:#fff;
}
</style>
这是Javascript:
this.imagePreview = function(){
/* CONFIG */
xOffset = 10;
yOffset = 30;
// these 2 variable determine popup's distance from the cursor
// you might want to adjust to get the right result
/* END CONFIG */
$("a.preview").hover(function(e){
this.t = this.title;
this.title = "";
var c = (this.t != "") ? "<br/>" + this.t : "";
$("body").append("<p id='preview'><img src='"+ this.href +"' alt='Image preview' />"+ c +"</p>");
$("#preview")
.css("top",(e.pageY - xOffset) + "px")
.css("left",(e.pageX + yOffset) + "px")
.fadeIn("fast");
},
function(){
this.title = this.t;
$("#preview").remove();
});
$("a.preview").mousemove(function(e){
$("#preview")
.css("top",(e.pageY - xOffset) + "px")
.css("left",(e.pageX + yOffset) + "px");
});
};
// starting the script on page load
$(document).ready(function(){
imagePreview();
});
这是主要的:
<a href="1.jpg" /*class="preview"*/><img src="1s.jpg" alt="gallery thumbnail" /></a>
最佳答案
我会用:
$('.preview').click(function(e) {
e.preventDefault();
return false;
});
(如果您删除class =“ preview”周围的评论)
关于javascript - 使用jQuery进行图像预览,如何删除href单击事件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10894364/