AngularJS ui-router, scroll to next step on state change

前端 未结 4 1750
攒了一身酷
攒了一身酷 2021-02-03 14:36

I\'m using UI-router in my app and I\'d like to so a simple \"scrollTo\" to an anchor when the URL/state changes. I don\'t want to load the next step from a template, or load a

4条回答
  •  無奈伤痛
    2021-02-03 14:47

    First. You need to define the state.

    .state('step1', {
        url: '/step-1'
    })
    

    Add onEnter controller (so you can $inject things).

    .state('step1', {
        url: '/step-1',
        onEnter: function () {}
    })
    

    Animate (or simply scroll) to element

    $('html, body').animate({
        scrollTop: $("#step1").offset().top
    }, 2000);
    

    Here the example

提交回复
热议问题