首页 \ 问答 \ 用户滚动时的AngularJS切换路径(AngularJS switch path when user scroll)

用户滚动时的AngularJS切换路径(AngularJS switch path when user scroll)

我试图检测用户何时滚动视图然后我想切换视图。

我在用户滚动时使用指令进行检测:

.directive("scroll", function ($window) {
return function(scope, element, attrs) {
    angular.element($window).bind("scroll", function() {
        if (this.pageYOffset >= 1) {
            scope.boolChangeClass = true;
            console.log('Scrolled down');
        } else {
            scope.boolChangeClass = false;
            console.log('Scroll up');
        }
        scope.$apply();
    });
};

使用ng-controller在div上调用该指令

<div scroll ng-controller="MyCtrl1">

我在Controller 1的视图中获得了boolChangeClass

   <span>{{boolChangeClass}}</span>

并将结果记录在我的控制器中

myApp.controller('MyCtrl1', ['$scope', '$http', function($scope, http) {
   console.log($scope.boolChangeClass);
}]);

如何在我的控制器中检测到boolChangeClass已更改,然后我想转到controller2?


I try to detect when the user scroll the view and then I would like to switch view.

I'm using a directive for detect when the user scroll :

.directive("scroll", function ($window) {
return function(scope, element, attrs) {
    angular.element($window).bind("scroll", function() {
        if (this.pageYOffset >= 1) {
            scope.boolChangeClass = true;
            console.log('Scrolled down');
        } else {
            scope.boolChangeClass = false;
            console.log('Scroll up');
        }
        scope.$apply();
    });
};

The directive is called on the div with the ng-controller

<div scroll ng-controller="MyCtrl1">

I get the boolChangeClass in the view of Controller 1

   <span>{{boolChangeClass}}</span>

And log the result in my controller

myApp.controller('MyCtrl1', ['$scope', '$http', function($scope, http) {
   console.log($scope.boolChangeClass);
}]);

How can I detect in my controller that boolChangeClass have changed and then I would like to go to controller2 ?


原文:https://stackoverflow.com/questions/45208500
更新时间:2023-04-30 14:04

最满意答案

转到c:\ Windows32 \ System \ drivers \ etc \ hosts.txt,取消注释127.0.0.1 localhost。 重启Chrome。


Goto c:\Windows32\System\drivers\etc\hosts.txt, uncomment the 127.0.0.1 localhost. Restart Chrome.

相关问答

更多
  • 尝试没有单引号: @font-face{ font-family: playtime; src: url('../fonts/font-1.otf') format('opentype'); } p.playtime-font { font-family: playtime; font-size: 3em; } 如果这不起作用,你的控制台是否会说什么? Try it without the single quotes: @font-face{ f ...
  • 转到c:\ Windows32 \ System \ drivers \ etc \ hosts.txt,取消注释127.0.0.1 localhost。 重启Chrome。 Goto c:\Windows32\System\drivers\etc\hosts.txt, uncomment the 127.0.0.1 localhost. Restart Chrome.
  • webfont很可能没有正确组装。 我已经下载了在Sebastian的网站上使用的CaviarDreams字体并得到了相同的bug。 然后我从这里下载了它: http : //www.dafont.com/caviar-dreams.font ,使用了fontsquirrel.com的typekit生成器 ,结果非常好。 It is highly likely that the webfont is not assembled properly. I have downloaded CaviarDreams ...
  • 本地运行( file:/// ) 默认情况下,Firefox附带了非常严格的“文件uri origin”( file:/// )策略:让它像其他浏览器一样运行,转到about:config ,通过fileuri过滤,并切换以下首选项: security.fileuri.strict_origin_policy 将其设置为false ,您应该能够跨不同路径级别加载本地字体资源。 出版网站 根据我以下的评论,您在部署网站后遇到此问题,您可以尝试添加一个附加标题来查看您的问题是否将自身配置为跨域问题:由于您指定了 ...
  • 您可能没有实际上传过字体文件。 这似乎导致了重定向,然后是服务器的404 Not Found响应。 (最初的问题是格式错误的@font-face规则,你在答案中修正了。) 这个问题似乎已经解决了。 You probably had not actually uploaded the font files. This seems to have caused a redirection and then a 404 Not Found response from a server. (The initial ...
  • 对于任何碰到这个的人。 答案归结为浏览器如何解析和加载CSS。 浏览器将在呈现页面之前等待加载所有css。 由于css / font主机的服务器很慢,它阻止了我的页面呈现。 我的解决方案是通过一个比字体托管公司更可靠的cdn服务来托管字体。 For anybody running into this. The answer boils down to how CSS is parsed and loaded by browsers. Browsers will wait for all css to be ...
  • 你需要确保字体导入只被调用一次。 因此,您应该删除所有从mixin文件导入的字体,因为您已经在答案中尝试过了。 但是,您还需要确保字体本身在您的应用中仍然存在,并且所有视图都可以访问它们。 您可能有一个像'app.less'或类似的文件,其中包含可在应用程序的所有部分中使用的样式。 从mixin中剪切字体导入,并将其放置在该文件中(确保路径引用仍然有效,可能需要调整它们)。 如果您还没有这样的文件,您需要创建一个并在应用程序启动时加载一次。 You need to make sure the font im ...
  • 为了解决这个问题,我不得不强制浏览器重绘。 将以下jquery放入,这会强制浏览器重绘。 $('body').hide().show(0); In order to fix this, I had to force the browser to redraw. Putting the following jquery in, this forces the browser to redraw. $('body').hide().show(0);
  • 也许这个CSS属性解决了你的问题: yourSelector { font-smooth: always; -webkit-font-smoothing: antialiased; } maybe this css property solves your problem: yourSelector { font-smooth: always; -webkit-font-smoothing: antialiased; }
  • 问题解决了。 Font Squirrel破坏了我的字体,所以我使用了fontface.codeandmore.com服务,他的@ font-face工具包完美地显示在任何浏览器上,包括Chrome(Windows)。 感谢大家的帮助! The problem was solved. Font Squirrel are broken my font, so I used fontface.codeandmore.com service, his @ font-face kit perfectly displa ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。