0

我想使用 /#/invoices/1?tab=2 之类的链接导航到我的单页应用程序的页面。此页面包含选项卡,因此我还想通过 url 将用户直接发送到我希望的选项卡。

您能否提供一些关于如何以最干净的方式实现这一点的指示?

4

2 回答 2

0

只是对上述答案的更新。

很少有自定义指令的例子

http://nadeemkhedr.com/angularjs-scroll-to-element-using-directives/

 angular.module('MyApp').directive('scrollToBookmark', function() {  
  return {
    link: function(scope, element, attrs) {
      var value = attrs.scrollToBookmark;
      element.click(function() {
        scope.$apply(function() {
          var selector = "[scroll-bookmark='"+ value +"']";
          var element = $(selector);
          if(element.length) {
            window.scrollTo(0, element[0].offsetTop – 100); 
            // Don’t want the top to be the exact element, -100 will go to the top for a little bit more
          }
        });
      });
    }
  };
});
于 2014-04-04T12:15:14.333 回答
0

使用$anchorScroll方法,在其上传递一个类名,您可以直接转到该元素。

于 2014-04-04T12:09:39.420 回答