0

I have an accordion element, and I need to have different panes expand on hashchange. The code I made, expands it but it doesn't scroll the the targeted div, and page never ends loading.

function hashChange() {
    if (window.location.hash === '#senior-backend') {
        $('#senior-backend, #backend-developer, #senior-frontend, #frontend, #dev-ops').hide(50);
        $('#senior-backend').show(50);
        $('#job-posts').removeClass().addClass('beige-bg');
        $('#job-posts-top').removeClass().addClass('beige-spikes');
    } 
}

window.onhashchange = hashChange;

Could you please point out what am I doing wrong.

Thanks

4

1 回答 1

1

一旦检测到哈希值发生变化,您需要滚动站点animate,例如:

var dest = $('#yourSelector').position();
var dtop = dest.top;

$('html, body').animate({
    scrollTop: dtop
});

现场演示:http: //jsfiddle.net/LZbK8/

于 2013-08-27T14:22:19.900 回答