Jquery 需要禁用图像映射上的单击事件
我有图像地图,我试图打开另一个页面使用JTip,但我需要这个页面应该只在鼠标上方。我的意思是,我不希望在映射图像上发生任何单击事件Jquery 需要禁用图像映射上的单击事件,jquery,Jquery,我有图像地图,我试图打开另一个页面使用JTip,但我需要这个页面应该只在鼠标上方。我的意思是,我不希望在映射图像上发生任何单击事件 <map name="Map" id="Map"> <area id="das" shape="rect" class="jTip" coords="222,84,342,147" href="resources/das.aspx" /> <area id="zirku" shape="rect" class="jTip" co
<map name="Map" id="Map">
<area id="das" shape="rect" class="jTip" coords="222,84,342,147" href="resources/das.aspx" />
<area id="zirku" shape="rect" class="jTip" coords="260,150,392,205" href="resources/zirku.aspx" />
<area shape="rect" id="mub" class="jTip" coords="337,229,489,285" href="resources/mub.aspx" />
<area shape="rect" id="sas" class="jTip" coords="543,239,668,292" href="resources/sas.aspx" />
<area shape="rect" id="ruw" class="jTip" coords="190,317,281,369" href="resources/ruw.aspx" />
<area shape="rect" id="hab" class="jTip" coords="386,382,485,436" href="resources/hab.aspx" />
<area shape="rect" id="asb" class="jTip" coords="500,480,569,532" href="resources/asb.aspx" />
</map>
Jquery是
$(document).ready(function(){
var toolTipActive = false;
$("area.jTip").hover(
function() {
var offsetX = 10;
var offsetY = 0;
var areaCoords = this.coords.split(',');
var mapPosition = $('img#image1').offset();
var tipTop = mapPosition.top + (areaCoords[1] * 1) + offsetY;;
var tipLeft = mapPosition.left + (areaCoords[2] * 1) + offsetX;
if (!toolTipActive)
JT_show(this.href,this.id,this.alt,tipLeft,tipTop);
toolTipActive = true;
},
function() {
JT_destroy();
toolTipActive =false;
}
);
});
function JT_destroy(){
$('div#JT').remove();
}
function JT_show(url,linkId,title,posX,posY){
if(title == false)title=" ";
var de = document.documentElement;
var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
var hasArea = w - getAbsoluteLeft(linkId);
var clickElementy = posY; //set y position
var queryString = url.replace(/^[^\?]+\??/,'');
var params = parseQuery( queryString );
if(params['width'] === undefined){params['width'] = 250};
if(params['link'] !== undefined){
$('#' + linkId).bind('click',function(){window.location = params['link']});
$('#' + linkId).css('cursor','pointer');
}
if(hasArea>((params['width']*1)+75)){
$("body").append("<div id='JT' style='width:"+params['width']*1+"px'><div id='JT_arrow_left'></div><div id='JT_close_left'>"+title+"</div><div id='JT_copy'><div class='JT_loader'><div></div></div>");//right side
var arrowOffset = getElementWidth(linkId) + 11;
//var clickElementx = getAbsoluteLeft(linkId) + arrowOffset; //set x position
var clickElementx = posX; //set x position
}else{
$("body").append("<div id='JT' style='width:"+params['width']*1+"px'><div id='JT_arrow_right' style='left:"+((params['width']*1)+1)+"px'></div><div id='JT_close_right'>"+title+"</div><div id='JT_copy'><div class='JT_loader'><div></div></div>");//left side
var clickElementx = getAbsoluteLeft(linkId) - ((params['width']*1) + 15); //set x position
}
$('#JT').css({left: clickElementx+"px", top: clickElementy+"px"});
$('#JT_copy').load(url);
$('#JT').show();
}
function getElementWidth(objectId) {
x = document.getElementById(objectId);
return x.offsetWidth;
}
function getAbsoluteLeft(objectId) {
// Get an object left position from the upper left viewport corner
o = document.getElementById(objectId)
oLeft = o.offsetLeft // Get left position from the parent object
//while(o.offsetParent!=null) { // Parse the parent hierarchy up to the document element
// oParent = o.offsetParent // Get parent object reference
// oLeft += oParent.offsetLeft // Add parent left position
// o = oParent
//}
return oLeft
}
function getAbsoluteTop(objectId) {
// Get an object top position from the upper left viewport corner
o = document.getElementById(objectId)
oTop = o.offsetTop // Get top position from the parent object
while(o.offsetParent!=null) { // Parse the parent hierarchy up to the document element
oParent = o.offsetParent // Get parent object reference
oTop += oParent.offsetTop // Add parent top position
o = oParent
}
return oTop
}
function parseQuery ( query ) {
var Params = new Object ();
if ( ! query ) return Params; // return empty object
var Pairs = query.split(/[;&]/);
for ( var i = 0; i < Pairs.length; i++ ) {
var KeyVal = Pairs[i].split('=');
if ( ! KeyVal || KeyVal.length != 2 ) continue;
var key = unescape( KeyVal[0] );
var val = unescape( KeyVal[1] );
val = val.replace(/\+/g, ' ');
Params[key] = val;
}
return Params;
}
function blockEvents(evt) {
if(evt.target){
evt.preventDefault();
}else{
evt.returnValue = false;
}
}
$(文档).ready(函数(){
var toolTipActive=false;
$(“area.jTip”)。悬停(
函数(){
var offsetX=10;
var offsetY=0;
var areaCoords=this.coords.split(',');
var mapPosition=$('img#image1').offset();
var tipTop=mapPosition.top+(areaCoords[1]*1)+offsetY;;
var tipLeft=mapPosition.left+(区域坐标[2]*1)+偏移量x;
如果(!ToolTiactive)
JT_show(this.href、this.id、this.alt、tipLeft、tipTop);
toolTipActive=true;
},
函数(){
JT_destroy();
toolTipActive=false;
}
);
});
函数JT_destroy(){
$('div#JT')。删除();
}
函数JT_show(url、linkId、标题、posX、posY){
如果(title==false)title=“”;
var de=document.documentElement;
var w=self.innerWidth | |(de&&de.clientWidth)| | document.body.clientWidth;
var hasArea=w-getAbsoluteLeft(linkId);
var clickElementy=posY;//设置y位置
var queryString=url.replace(/^[^\?]+\??/,“”);
var params=parseQuery(queryString);
如果(params['width']==未定义){params['width']=250};
if(参数['link']!==未定义){
$('#'+linkId).bind('click',function(){window.location=params['link']});
$('#'+linkId).css('cursor','pointer');
}
如果(hasArea>((参数['width']*1)+75)){
$(“正文”).append(“+title+”);//右侧
var arrowOffset=getElementWidth(linkId)+11;
//var clickElementx=getAbsoluteLeft(linkId)+箭头偏移;//设置x位置
var clickElementx=posX;//设置x位置
}否则{
$(“正文”).append(“+title+”);//左侧
var clickElementx=getAbsoluteLeft(linkId)-(参数['width']*1)+15);//设置x位置
}
$('#JT').css({左:clickElementx+“px”,上:clickElementy+“px”});
$('JT#u copy')。加载(url);
$('#JT').show();
}
函数getElementWidth(objectId){
x=document.getElementById(objectId);
返回x.offsetWidth;
}
函数getAbsoluteLeft(objectId){
//从左上角视口获取对象的左位置
o=document.getElementById(objectId)
oLeft=o.offsetLeft//从父对象获取左位置
//while(o.offsetParent!=null){//将父层次结构解析到文档元素
//oParent=o.offsetParent//获取父对象引用
//oLeft+=oParent.offsetLeft//添加父级左位置
//o=不透明
//}
回油
}
函数getAbsoluteTop(objectId){
//从左上角视口获取对象顶部位置
o=document.getElementById(objectId)
oTop=o.offsetTop//从父对象获取顶部位置
while(o.offsetParent!=null){//将父层次结构解析到文档元素
oParent=o.offsetParent//获取父对象引用
oTop+=oParent.offsetTop//添加父顶级位置
o=不透明
}
返回oTop
}
函数parseQuery(查询){
var Params=新对象();
if(!query)返回参数;//返回空对象
var Pairs=query.split(/[;&]/);
对于(变量i=0;i
试试这个
$(function(){
$("#Map area").unbind('click').removeAttr("onclick")[0].onclick = null;
});
只需单击返回false,如下所示:
$('area.jTip').click(function(){ return false; });
将其与其他代码组合在一起:
$(document).ready(function(){
var toolTipActive = false;
$("area.jTip").hover(
function() {
var offsetX = 10;
var offsetY = 0;
var areaCoords = this.coords.split(',');
var mapPosition = $('img#image1').offset();
var tipTop = mapPosition.top + (areaCoords[1] * 1) + offsetY;;
var tipLeft = mapPosition.left + (areaCoords[2] * 1) + offsetX;
if (!toolTipActive)
JT_show(this.href,this.id,this.alt,tipLeft,tipTop);
toolTipActive = true;
},
function() {
JT_destroy();
toolTipActive =false;
}
).click(function(){ return false; });
});
$('area.jTip')。单击(函数(事件){event.preventDefault();返回false;})