var $a = $("a");
var topValue = $("#four-choices").offset().top * 1.5 + ($("two-wide-cols").height());
var prevTarget = "#tabletop";
$(document).ready(function($) {
$("#fabric,#throws,#lighting").hide();
$a.click(function(event) {
event.preventDefault();
target = $(this).attr("href");
scrollToTarget(target, prevTarget);
});
});
function scrollToTarget(target, prevTarget) {
if (target == prevTarget) return false;
$(prevTarget).fadeOut("slow");
$(target).fadeIn("slow");
$("html,body").animate({
scrollTop: topValue
}, 1000, function() {
window.location.hash = target;
prevTarget = target;
console.log("window.prevTarget:" + window.prevTarget + ",prevTarget: " + prevTarget)
});
}
这个地方: 因为参数的名字和全局的名字相同,所以更新的值只是局部prevTarget的值,但是全局变量的值并未发生更新