저는이 웹 페이지를 개선하기 위해 노력해 왔으며 다음 코드를 볼 때 모두 웃을 것이라고 확신합니다. 그러나 제가가는대로 스스로 가르치고 있습니다. 나는 내 자신을 얼마나 멀리 할 수 있었는지 조금 자랑 스럽다. 문제는지도에서 여러 도시를 클릭하기 시작하면 내가 한 일은 다소 버그가있는 것이지요. 알아낼만큼 정통하지는 않습니다. 또한 코드를 작동시키는 데 긴 경치 좋은 길을 택 했으므로 누구나 코드 작성 방법을이 사람에게 가르쳐 줄 수 있기를 희망합니다.버그 수정 및 자바 스크립트 코드 최적화에 도움이 필요합니다.
당신은 여기에 전체 개발 볼 수 있습니다 http://buhmanphotography.com/map/buggyCode/
$(document).ready(function() {
// Show the Map Container
$('.locBox a').click(function (e) {
// Initialize info for clicked location
var initLocInfo = $(this).attr("rel") + "Ctn";
// Show Initial Information
$('#' + initLocInfo).show();
$('#' + initLocInfo).css('opacity','1');
$('#' + initLocInfo).addClass('modActive');
// Initialize Button State on Map
var initLocBtn = $(this).attr("rel") + "Btn";
$('#' + initLocBtn).css('backgroundPosition','top');
// Open Map Box
$("#mapModalCtn").show();
$("#mapModalCtn").animate({
opacity: 1
}, 500);
e.preventDefault();
});
// Hide the Map Container
$('#modalTitle a').click(function (e) {
$("#mapModalCtn").animate({
opacity: 0
}, 500, function() {
$("#mapModalCtn").hide();
$('#modLeftCol > div').removeClass('modActive');
$('#modLeftCol > div').hide();
$('#modRightCol a').css('backgroundPosition','bottom');
});
e.preventDefault();
});
// Show the info for the selected Location on the Map
$('#modRightCol a').click(function (e) {
e.preventDefault();
var locInfo = $(this).attr("rel") + "Ctn";
var locBtn = $(this).attr("rel") + "Btn";
// Change Map Location Button State
$('#modRightCol a').css('backgroundPosition','bottom');
$(this).css('backgroundPosition','top');
// Hide currently visible information
if ($('#modLeftCol > div').hasClass('modActive')) {
$("#modLeftCol > div").animate({
opacity: 0
}, 500, function(){
$("#modLeftCol > div").hide();
$("#modLeftCol > div").removeClass('modActive');
//Show information related to location clicked
$('#' + locInfo).show();
$('#' + locInfo).animate({
opacity: 1
}, 500, function(){
$('#' + locInfo).addClass('modActive');
});
});
}
});
});
[jQuery 선택기 캐싱에 대한 내 질문] (http://stackoverflow.com/questions/5724400/does-using-this-instead-of-this-provide-a-performance-enhancement)을 참조하십시오. –
http : //codereview.stackexchange에 더 적합 할 수 있습니다.com /,하지만 Jared의 코멘트에 더 가까운 시간에 jQuery 메서드를 사용할 수 있습니다 : $ ('#'+ initLocInfo) .show() .css ('opacity', '1'). addClass ('modActive');'(동일한 요소를 반복적으로 선택하는 것이 더 효율적 임). 당신의 코멘트에 관해서는 "내가 한 것은 약간의 버그"입니다 - 당신은 더 구체적 일 필요가 있습니다. – nnnnnn
링크를 이용해 주셔서 감사합니다. 특별한 리뷰 영역이 있다는 것을 몰랐습니다. 지도에서 다른 도시를 몇 번 클릭 한 후 그 버기를 말하면 왼쪽에있는 제목이 이전 선택과 방금 선택한 항목 사이를 번갈아 깜박입니다. 그것이 타이밍 문제인지 궁금합니다 - 이전 스크립트가 완료되기 전에 다른 도시를 쳤다면 그렇게 할 수 있습니다. Safari와 Firefox에서 모두 보입니다. – lbweb