AngularJS“scrollTop的”等价? [英] AngularJS 'scrollTop' equivalent?

查看:128
本文介绍了AngularJS“scrollTop的”等价?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我期待实现在AngularJS指令类似于这样:

<一个href=\"https://github.com/geniuscarrier/scrollToTop/blob/master/jquery.scrollToTop.js\">https://github.com/geniuscarrier/scrollToTop/blob/master/jquery.scrollToTop.js

这是相当简单的,当你不在它会在一个按钮淡出滚动到页面顶部的顶部:

  $(窗口).scroll(函数(){
                如果($(本).scrollTop()→100){
                    $ this.fadeIn();
                }其他{
                    $ this.fadeOut();
                }
            });

不过我有一个很难找到如何在角获取当前的滚动位置。我宁愿没有使用jQuery只为这一件事情。

谢谢!


解决方案

  $ window.pageYOffset

这是从服务窗口$属性。

I'm looking to implement something similar to this in an AngularJS directive:

https://github.com/geniuscarrier/scrollToTop/blob/master/jquery.scrollToTop.js

It's fairly straightforward, when you are not at the top of the page it will fade in a button to scroll to the top:

 $(window).scroll(function() {
                if ($(this).scrollTop() > 100) {
                    $this.fadeIn();
                } else {
                    $this.fadeOut();
                }
            });

However I'm having a hard time finding how to get the current scroll location in Angular. I'd rather not have to use jQuery just for this single thing.

Thanks!

解决方案

$window.pageYOffset

This is property from service $window

这篇关于AngularJS“scrollTop的”等价?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆