Maybe this isn't possible with ASP.NET MVC because I can not find an answer. What I want to do is click a link which will load the target page then scroll to anchor on that page. A perfect example of this was answered in this question.
However how do I get this to work with JavaScript/jQuery?
UPDATE:With this code everything is working except for the setTimeOut definition. It just keeps running the script until I click stop, then if scrolls down to the anchor. Why is that?
var jump = function (e) {
if (e) {
e.preventDefault();
var target = $(this).attr("href");
} else {
var target = location.hash;
}
$('html,body').animate(
{
scrollTop: $(target).offset().top
}, 2000, function () {
location.hash = target;
});
}
$('html, body').hide();
$(document).ready(function () {
$('a[href^=#]').bind("click", jump);
if (location.hash) {
setTimeout(function () {
$('html, body').scrollTop(0).show();
jump();
}, 0);
} else {
$('html, body').show();
}
});