У меня есть простая карта со ссылками и щелчком, содержимое исчезает и заменяет другое.
Проблема: каждый контент скрыт при первом посещении, как я могу сказать jquery, что должен отображаться первый блок контента "map_overview", а остальная часть содержимого скрыта до тех пор, пока они не будут привязаны к связанной ссылке.
Код HTML:
<div id="suburbanmap">
<div id="stmap">
<a class="stmaplink stmap-overview" id="show_overview">Overview</a>
<a class="stmaplink stmap-content1" id="show_content1">Link to content 1</a>
<a class="stmaplink stmap-content2" id="show_content2">Link to content 2</a>
<a class="stmaplink stmap-content3" id="show_content3">Link to content 3</a>
</div>
<div id="mapcontent">
<div id="map_overview" class="stmc stmc-overview">
<h3>Overview</h3>
Example Text of the the overview introduction. This content is the first which will be shown and has to be displayed while the rest is hidden.
</div>
<div id="map_content1" class="stmc stmc-content1">
<h3>Content 1</h3>
</div>
<div id="map_content2" class="stmc stmc-content2">
<h3>Content 2</h3>
</div>
<div id="map_content3" class="stmc stmc-content3">
<h3>Content 3</h3>
</div>
</div>
</div>
Код CSS:
#mapcontent .stmc { display: none; width: 550px; float: left; }
Код JQuery:
$("#stmap a").click(function(){
var id = $(this).attr('id');
id = id.split('_');
$("#mapcontent .stmc").fadeOut(500).hide();
$("#mapcontent #map_"+id[1]).fadeIn(500).show();
var maplinks = $("#stmap a");
maplinks.click(function () {
maplinks.removeClass('active');
$(this).addClass('active');
});
});
jquery основан на stackoverflow и изменен. Может, у кого-то есть решение?
Скажите, чтобы он запускал событие щелчка при загрузке документа.
$(document).ready(function() {
$('#map_overview').click();
});
Или просто установите экран для блокировки для этого конкретного div, либо установив встроенный стиль, либо используя jQuery:
<div id="map_overview" class="stmc stmc-overview" style="display:block">
или
$(document).ready(function() {
$('#map_overview').css('display', 'block');
});
$("#stmap a").first().triggerHandler('click')