這其中有兩個標記打開和關閉。檢查jsfiddle的所有更改。我不得不重新構建一些代碼。
function createSwitches(markers){
var html = '<div class="switches"><span class="switch-title">Show Me</span></div>';
// ADD YOU SWITCHES HERE!
// Make sure the same order as the google markers
var all_switches = [
{
html: '<span class="whats-on-wrapper"><span data-target="whats-on" class="switch switch-on">Item Group 2</span></span>',
},
{
html: '<span class="stand-wrapper"><span data-target="stand" class="switch switch-on">Item Group 1</span></span>',
}
];
// Add the main bar element
$('.map-container').prepend(html);
// Loop through all your switches and add them
// with the event
for (var i = 0; i < all_switches.length; i++) {
var element = $(all_switches[i]["html"]);
(function(index, element, markers) {
$(element).on('click', function() {
var this_marker = markers[index];
var current = String(this_marker.visible);
var toggle = (current === "true") ? false : true;
this_marker.setVisible(toggle);
});
})(i, element, markers)
$('.switches').append($(element))
}
// Set the toggle animation
$('.switches .switch').click(function(){
$(this).toggleClass('switch-on');
$(this).toggleClass('switch-off');
});
}
https://jsfiddle.net/6n25g3n7/8/
來源
2016-06-07 07:25:15
wot
嗨Weigreen,感謝您的答覆 - 我檢查了小提琴,但它是完全一樣的我一個,有沒有變化:( – PavKR
@thePav對不起更新的鏈接:) – weigreen
真棒! , 感謝那!現在有沒有辦法將標記分組並將它們綁定到它們的開關? – PavKR