Ember.js anchor link

后端 未结 7 1070
时光说笑
时光说笑 2020-12-08 05:22

I have a login box on homepage that I need to link to. The login box has id=\"login\" in html and I have a link to it like this

  • 7条回答
    •  时光取名叫无心
      2020-12-08 06:08

      I use a component, which could also be extended to support query params via an action.

      var ScrollToComponent = Ember.Component.extend({
        tagName: 'a',
        anchor: '',
      
        scrollTo: function () {
          var anchor = this.get('anchor'),
            $el = Ember.$(anchor);
      
          if ($el) {
            Ember.$('body').scrollTop($el.offset().top);
          }
        }.on('click')
      });
      

      This is how you'd use it:

      {{#scroll-to anchor=anchor}}Jump To Anchor{{/scroll-to}}
      

      Where anchor is #my-id.

      Edit

      Here's an ember-cli addon that does this https://www.npmjs.com/package/ember-scroll-to

    提交回复
    热议问题