我有这个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 atrribute中指定的链接时,在页面加载后执行javascript代码,因此页面滚动到 div部分即可。使用此代码,滚动效果仅在加载页面后起作用,但不适用于用户单击地图时的第一次。在地图点击后加载页面后可以滚动吗?