jQuery Imagemapster多点单击状态
我想使用实现多状态着色 换句话说,当一个区域单击一次时,它将以绿色突出显示,如果单击两次,它将以红色突出显示,第三次单击将重置为无颜色 我一直在阅读文档并查看演示,但不知道如何实现这一点。感谢您的帮助jQuery Imagemapster多点单击状态,jquery,map,mapping,imagemap,imagemapster,Jquery,Map,Mapping,Imagemap,Imagemapster,我想使用实现多状态着色 换句话说,当一个区域单击一次时,它将以绿色突出显示,如果单击两次,它将以红色突出显示,第三次单击将重置为无颜色 我一直在阅读文档并查看演示,但不知道如何实现这一点。感谢您的帮助 ImageMapster是我遇到的最健壮但最轻量级的图像映射jQuery插件,因此,除非有人知道另一个具有此功能的插件,否则我将坚持使用此插件。以下是使用ImageMapster跟踪三种状态的示例: 基本技巧是,您必须自己跟踪每个区域的状态,并告诉ImageMapster要做什么。代码如下: v
ImageMapster是我遇到的最健壮但最轻量级的图像映射jQuery插件,因此,除非有人知道另一个具有此功能的插件,否则我将坚持使用此插件。以下是使用ImageMapster跟踪三种状态的示例: 基本技巧是,您必须自己跟踪每个区域的状态,并告诉ImageMapster要做什么。代码如下:
var map = $('#map'),
// a object map for tracking the state of each area
selStates = {},
// rendering options for the 1st selected state
selected1opts = {
fillColor: '00ff00',
stroke: true,
strokeColor: '000000',
strokeWidth: 2
},
// rendering options for the 2nd selected state
selected2opts = {
fillColor: 'ff0000',
stroke: true,
strokeColor: '00ff00',
strokeWidth: 1
};
// make an array from the different states' rendering options so we can easily
// choose one
var renderOpts = [selected1opts, selected2opts];
function onClick(data) {
// get current state (0,1,2) -- default to zero which means unset
var cur = selStates[data.key] || 0,
next = (cur + 1) % 3;
// always unset: if state 0, this is all we need to do. if state
// 2, we have to unset first, since setting the state for an area
// that's already selected will do nothing. If it happens to be going from
// 0 to 1, then no harm done.
map.mapster('set', false, data.key);
if (next) {
// now set the area state using the correct options
map.mapster('set', true, data.key, renderOpts[cur]);
}
// update local store with current state
// add 1, and apply a modulus of 3 to get new state
selStates[data.key] = next;
}
map.mapster({
mapKey: 'state',
// setting isSelectable=false will prevent imagemapster from using its own click-select
// handling. You could also return false from the onClick event to stop internal handling
isSelectable: false,
// bind our "onClick" function above to handle area clicks
onClick: onClick
});
以下是使用ImageMapster跟踪三种状态的示例: 基本技巧是,您必须自己跟踪每个区域的状态,并告诉ImageMapster要做什么。代码如下:
var map = $('#map'),
// a object map for tracking the state of each area
selStates = {},
// rendering options for the 1st selected state
selected1opts = {
fillColor: '00ff00',
stroke: true,
strokeColor: '000000',
strokeWidth: 2
},
// rendering options for the 2nd selected state
selected2opts = {
fillColor: 'ff0000',
stroke: true,
strokeColor: '00ff00',
strokeWidth: 1
};
// make an array from the different states' rendering options so we can easily
// choose one
var renderOpts = [selected1opts, selected2opts];
function onClick(data) {
// get current state (0,1,2) -- default to zero which means unset
var cur = selStates[data.key] || 0,
next = (cur + 1) % 3;
// always unset: if state 0, this is all we need to do. if state
// 2, we have to unset first, since setting the state for an area
// that's already selected will do nothing. If it happens to be going from
// 0 to 1, then no harm done.
map.mapster('set', false, data.key);
if (next) {
// now set the area state using the correct options
map.mapster('set', true, data.key, renderOpts[cur]);
}
// update local store with current state
// add 1, and apply a modulus of 3 to get new state
selStates[data.key] = next;
}
map.mapster({
mapKey: 'state',
// setting isSelectable=false will prevent imagemapster from using its own click-select
// handling. You could also return false from the onClick event to stop internal handling
isSelectable: false,
// bind our "onClick" function above to handle area clicks
onClick: onClick
});