-1
我與谷歌地圖的工作,我有標記的數組,它看起來像這樣:jquery css顏色正在改變每個選擇器,但字體大小不是?
var locations = [
[{
id: 1,
lat: 51.5239935252832,
lng: 5.137663903579778,
content: 'Kids Jungalow (5p)'
}],
[{
id: 2,
lat: 51.523853342911906,
lng: 5.1377765563584035,
content: 'Kids Jungalow (5p)'
}],
[{
id: 3,
lat: 51.5237298485607,
lng: 5.137969675407476,
content: 'Kids Jungalow (5p)'
}],
[{
id: 4,
lat: 51.52355628836575,
lng: 5.138066234932012,
content: 'Kids Jungalow (5p)'
}],
[{
id: 5,
lat: 51.52340275379578,
lng: 5.138211074218816,
content: 'Kids Jungalow (5p)'
}],
[{
id: 6,
lat: 51.523199152806626,
lng: 5.138382735595769,
content: 'Kids Jungalow (5p)'
}],
[{
id: 7,
lat: 51.5229955509073,
lng: 5.138511481628484,
content: 'Kids Jungalow (5p)'
}],
[{
id: 8,
lat: 51.52280529912936,
lng: 5.138543668136663,
content: 'Kids Jungalow (5p)'
}],
[{
id: 9,
lat: 51.523596340777075,
lng: 5.138463201866216,
content: 'Kids Jungalow (5p)'
}],
[{
id: 700,
lat: 51.523372714362736,
lng: 5.1386992362595265,
content: 'Kids Jungalow (5p)'
}],
[{
id: 101,
lat: 51.52329594683302,
lng: 5.138838711128301,
content: 'Kids Jungalow Giraffe'
}]
比我環槽標記列陣和一個HTML標記組這樣的每一個位置:
for (i = 0; i < locations.length; i++) {
var myLatLng = new google.maps.LatLng({
lat: locations[i][0].lat,
lng: locations[i][0].lng
});
var number = locations[i][0].id;
var marker_html = '<div id="' + number + '"><div class="rich-marker"><span class="number-id">' + number + '</span></div></div>';
var marker = new RichMarker({
position: myLatLng,
map: map,
flat: true,
anchor: RichMarkerPosition.MIDDLE,
content: marker_html
});
}
比我想改變類number-id
的CSS樣式縮放級別18這樣的:
map.addListener('zoom_changed', function() {
// Limit the zoom level
if (map.getZoom() < minZoomLevel) map.setZoom(minZoomLevel);
// for loop door locaties
for (i = 0; i < locations.length; i++) {
setMarkerSize(i);
}
});
function setMarkerSize(i) {
var infobox = locations[i][0].infobox;
var id = locations[i][0].id;
if (map.getZoom() === 18) {
$('.rich-marker').css({ 'display' : 'block', 'width' : '20px', 'height' : '20px' });
$('.number-id').css({ 'display' : 'block', 'font-size' : '12px'});
if (id >= 100) {
console.log(id);
console.log($('[data-id="' + id + '"]'));
$('#' + id).find('.number-id').css('font-size', '10px');
$('#' + id).find('.number-id').css('color', 'red');
}
infobox.setOptions({ pixelOffset: new google.maps.Size(-93, -22) });
}
}
的顏色是改變所有100以上,但字體大小隻改變爲數組中的最後一個對象爲什麼?
'如果(ID> = 100){'這裏其中是的'id'從未來值? – dreamweiver
@dreamweiver抱歉忘了提及一個 – Sreinieren
因爲id不是在循環中構造的,所以它的值在if內部是常量,所以選擇器$('#'+ id).find('。number-id')'會只有唯一的值,因爲使用了id選擇器,這意味着css將無法應用於具有id> = 100的所有元素。 – dreamweiver