0

I have a list of div elements, when the customer selected an element, the detail view appear. After the back, i want to target my list on selected element.

<div id="patient{{patient.PId}}" class="div-patient" ng-repeat="patient in patients">
   <p>{{patient.name}}</p>
</div>

I have tested many code to scroll on a selected patient:

$(window).scrollTop($("#patient"+$rootScope.selectedPatient).offset().top);
// or
$("html, body").animate({ scrollTop:angular.element("#patient"+$rootScope.selectedPatient).prop( 'offsetTop' ) });
//or
$(window).scrollTop(angular.element("#patient"+$rootScope.selectedPatient).prop( 'offsetTop' ));

The css div-patient:

position: absolute;
height: 330px;
margin-bottom: 30px;
top: {{360*fixTopCell($index)}}px;

But

$("#patient"+$rootScope.selectedPatient).offset().top

and

angular.element("#patient"+$rootScope.selectedPatient).prop( 'offsetTop' )

Return 0 all the time.

It works when I use a table tag instead of a div.

I see that the function scrollTop is not available in Android 4.X. Are there others solutions to target the element selected after a back on list?

R3tep
  • 12,512
  • 10
  • 48
  • 75
  • How about this? $("#patient"+$rootScope.selectedPatient)[0].offsetTop – allenhwkim Jan 14 '14 at 15:52
  • 1
    Besides your question, You are overusing jquery!!! http://stackoverflow.com/questions/14994391/how-do-i-think-in-angularjs-if-i-have-a-jquery-background?lq=1 – Ilan Frumer Jan 14 '14 at 15:52
  • @Ilan Frumer I use JQuery in directive.js. It's a problem? – R3tep Jan 14 '14 at 16:03
  • First let me see your code. The way you use **selectors** is probably not "the angular way". – Ilan Frumer Jan 14 '14 at 16:08
  • @IlanFrumer Sorry but this is not exactly my code. I can not publish the real source code of this appplication. – R3tep Jan 15 '14 at 10:14
  • as @JeffAtwood says: `in a world of small and large businesses using .NET that really aren't interested in sharing their code with the world – probably because they know it would suck if they did, anyway.` -> [link](http://www.codinghorror.com/blog/2013/03/why-ruby.html) – Ilan Frumer Jan 15 '14 at 10:43
  • 1
    @IlanFrumer I am agree with this but my boss didn't... and i like my job^^ – R3tep Jan 15 '14 at 12:28

1 Answers1

1

It works when i use a table tag INSTEAD of a div.

Make sure your id is not already used #patient. Maybe you try to call an id already used!

Chéramy Alexandre
  • 444
  • 3
  • 8
  • 25