我有这个 HTML 标记:
<asp:Image ID="imgMap" runat="server" ImageUrl="/common/images/harita.jpg" class="map"
usemap="#Map" BorderWidth="0" />
<map name="Map" id="Map">
<area title="City1" shape="poly" coords="266,103" href="/dealer/186/Page.aspx#dealer1" />
<area title="City2" shape="poly" coords="255,222" href="/dealer/186/Page.aspx#dealer2" />
</map>
和
<div id="dealer1"></div>
<div id="dealer2"></div>
.
.
.
.
和这样的Javascript代码:
<script type="text/javascript">
$(window).ready(function () {
var addressSection = "",
dealer = "",
eTop = "",
callbackAnimate = function () {
setTimeout(function () {
$(dealer).removeAttr("style").fadeIn();
}, 1000);
},
animateScroll = function () {
$('html, body').animate({ scrollTop: eTop }, 1000, function () {
$(dealer).effect("highlight", { color: "#fd9900" }, 500, callbackAnimate);
});
};
$('#Map').find('area').each(function (index, elArea) {
$(this).click(function () {
addressSection = $(this).attr('href').split('#');
dealer = "#" + addressSection[addressSection.length - 1];
eTop = $(dealer).offset().top;
animateScroll();
});
});
});
</script>
我想要实现的是当用户单击图像区域并且页面转到href属性中指定的链接时,在页面加载后执行 javascript 代码,因此页面滚动到div部分。使用此代码,滚动效果仅在页面加载后有效,但在用户第一次单击地图时无效。是否可以在地图点击加载页面后进行滚动?