用户滚动时的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
最满意答案
转到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 ...
-
与Chrome的悲伤面孔(Sad face with Chrome)[2022-04-07]
转到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-face未在Chrome中显示(Windows)[关闭](@font-face not displayed in Chrome (Windows) [closed])[2022-03-26]
问题解决了。 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 ...