简体   繁体   English

检查用户是否在页面上的特定位置

[英]Check if the user is on a certain location on the page

I have an Angular application that has multiple accordion groups. 我有一个具有多个手风琴组的Angular应用程序。 They are closed by default. 它们默认是关闭的。 One section is quite large so when it opens, the users need to scroll down if they want to see the end of the section. 一个部分很大,因此当它打开时,用户需要向下滚动才能看到该部分的结尾。 This section has some calculations on it. 本节对此进行了一些计算。 The problem is that I have a calculate button on the top of the section so when the user wants to recalculate it they have to scroll to the top again to see the button. 问题是我在该部分的顶部有一个计算按钮,因此当用户要重新计算它时,他们必须再次滚动到顶部才能看到该按钮。

Is there any possibility to get the location when the user reached a certain location so it would trigger a ng-if with an overlay button. 当用户到达某个位置时,是否有可能获得该位置,因此它会通过覆盖按钮触发ng-if。

Thanks, Brent 谢谢,布伦特

You can use the JQuery .scroll(), it might look like this: 您可以使用JQuery .scroll(),它看起来可能像这样:

 var app = angular.module('myApp', []); app.controller('myCtrl', function($scope, $document) { $scope.pos = { scrollPos:0 }; $("#outer").scroll(function() { $scope.pos.scrollPos = $("#outer").scrollTop().valueOf(); $scope.$apply(); }); }); 
 #outer { overflow: auto; height: 250px; width: 200px; border: solid 1px #ccc; } .inner { height: 1000px; position: relative; width: 198px; } .top { position: absolute; top: 0px; } .bottom { position: absolute; bottom: 0px; } .scrolled { position: fixed; top: 30px; } 
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div ng-app="myApp" ng-controller="myCtrl"> {{pos.scrollPos}}<br> <div id="outer"> <div class="inner"> <div class="scrolled ng-hide" ng-show="pos.scrollPos > 50">Passed Point.</div> <div class="top">Top</div> <div class="bottom">Bottom</div> </div> </div> </div> 

Yes this can be achieved with javascript try reading through this article on Mozilla it will help you achieve your goal, basically it lets you know the position of the mouse on the client. 是的,这可以用JavaScript尝试通过阅读来实现这个文章在Mozilla它会帮助你实现你的目标,基本上它可以让你知道在客户端上鼠标的位置。 Apart from this if there is a specific element on the page that you need to know if the cursor is inside you can use Jquery and mouseenter event and then trigger some action. 除此之外,如果页面上有一个特定的元素需要知道光标是否在其中,则可以使用Jquery和mouseenter事件 ,然后触发一些操作。

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

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