简体   繁体   English

ngSmoothScroll angular指令不起作用

[英]ngSmoothScroll angular directive not working

I'm using the following directive https://github.com/d-oliveros/ngSmoothScroll to make stuff in this project smoothly scroll to the selected element. 我正在使用以下指令https://github.com/d-oliveros/ngSmoothScroll使该项目中的内容顺利滚动到所选元素。

Here's my code: 这是我的代码:

...
<!-- build:js(.) scripts/vendor.js -->
    <!-- bower:js -->
    <script src="bower_components/jquery/dist/jquery.js"></script>
    <script src="bower_components/angular/angular.js"></script>
    <script src="bower_components/bootstrap/dist/js/bootstrap.js"></script>
    <script src="bower_components/angular-animate/angular-animate.js"></script>
    <script src="bower_components/angular-aria/angular-aria.js"></script>
    <script src="bower_components/angular-cookies/angular-cookies.js"></script>
    <script src="bower_components/angular-messages/angular-messages.js"></script>
    <script src="bower_components/angular-resource/angular-resource.js"></script>
    <script src="bower_components/angular-route/angular-route.js"></script>
    <script src="bower_components/angular-sanitize/angular-sanitize.js"></script>
    <script src="bower_components/angular-touch/angular-touch.js"></script>
    <!-- endbower -->
    <!-- endbuild -->
    <script src="bower_components/ngSmoothScroll/dist/angular-smooth-scroll.min.js"></script>
        <!-- build:js({.tmp,app}) scripts/scripts.js -->
        <script src="scripts/app.js"></script>
        <script src="scripts/controllers/initcontroller.js"></script>
        <!-- endbuild -->
        <script src="scripts/libs/materialize.min.js"></script>
        <script src="scripts/libs/angular-materialize.js"></script>
</body>
...

That's where the script is included (~/angular-smooth-scroll.min.js) and inside my app.js file I have: 这是包含脚本的地方(~/angular-smooth-scroll.min.js) ,在我的app.js文件中,我有:

angular
  .module('sccateringApp', [
    'ngAnimate',
    'ngAria',
    'ngCookies',
    'ngMessages',
    'ngResource',
    'ngRoute',
    'ngSanitize',
    'ngTouch',
    'ui.materialize',
    'smoothScroll'
  ])

'smoothScroll' being the actual dependency inclusion to the project. 'smoothScroll'是项目的实际依赖包含。 Following the instructions inside the link given at the beginning of this post this is what I do inside my view: 按照本文开头给出的链接中的说明,这是我在视图中所做的:

<li><a href="#" scroll-to="service-info" container-id="service-info">Contáctame</a></li>
...

<section class="service-info" id="service-info">
<h1 class="sofia-font">Detalles de Servicio</h1>
...

However, there is no smooth scroll happening and also, there are no warnings/errors given by either the console or jslint on my grunt serve task. 但是,没有平滑的滚动发生,并且在我的grunt serve任务中没有控制台或jslint给出的警告/错误。

Any idea what I might be doing wrong? 知道我可能做错了什么吗? I'm VERY new to angular and I'm still trying to find my way through it. 我对角度非常新,我仍然试图找到它的方式。

I'm not sure but it may be because you are using the container-id on a link and not a non-anchor tag. 我不确定,但可能是因为您在链接上使用container-id而不是非锚标记。 I'm using this to scroll to an element in my footer. 我正在使用它滚动到我的页脚中的元素。 My code is: 我的代码是:

//the anchor link in my nav
 <a href="#" scroll-to="footer" duration="2500">Click Me</a>
 ...

//the element I want to scroll to
 <div id="footer"></div>
 ...

The minified version wasn't working for me so my scripts go as follows: 缩小版本对我不起作用所以我的脚本如下:

<script src="/bower_components/angular/angular.js"></script>
<script src="/bower_components/angular-animate/angular-animate.js"></script>
<script src="/bower_components/angular-aria/angular-aria.js"></script>
<script src="/bower_components/angular-messages/angular-messages.js"></script>
<script src="/bower_components/angular-material/angular-material.js"></script>
<script src="/bower_components/angular-sanitize/angular-sanitize.js"></script>

<script src="/bower_components/ngSmoothScroll/lib/angular-smooth-scroll.js"></script>

<script src="/js/app.module.js"></script>
<script src="/js/app.controller.js"></script>
<script src="/js/app.service.js"></script>

And for the module: 对于模块:

angular
   .module('glasser', [
      'ngMaterial',
      'ngSanitize',
      'smoothScroll'
    ])

It didn't work for me either, try Angular-Scroll instead. 它对我来说也不起作用,请尝试使用Angular-Scroll It has a live demo to test in your browser first. 它有一个现场演示,首先在浏览器中进行测试。

It also has a 'spy' directive so you can add classes to elements that are in view. 它还有一个'间谍'指令,因此您可以将类添加到视图中的元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM