javascript - How to use angularjs $anchorScroll on div only if div is hidden? -



i'm using angularjs develop web application. have several nested div. each of them correspond item user can select.
example of div display in official angularjs documentation :
http://plnkr.co/edit/qncmfyjpup2r0vuz0ax8?p=preview

in code each div have ng-click="gotoanchor(x)" event when click on div if partially hidden, pull on page , user can see clicked div.
have header in page first div anchor , click event not directly @ top of page. , if click on first div, scroll , header won't visible.

question is, there way activate anchor if div isn't displayed on screen ?

if have other solution anchors, take it.

thank in advance.

if understand question correctly issue when using $anchorscroll header either

a: being covered div scrolled frame,

or

b partially covering div scrolled frame.

either way there 2 solutions should review:

first

make sure you're employing css layer elements, header (if fixed) should have z-index supersedes divs.

.header  { position: fixed; top:0; width: 100%; z-index: 99} .content { position: relative; margin-top: 10px; z-index: 1;} 

remember z-index works on positional elements (see ref)

second

employ $anchorscrollofset make sure scroll distance bumped down compensate header height. seen in angular docs, can use method in application:

.run(['$anchorscroll', function($anchorscroll) {   $anchorscroll.yoffset = 50;   // scroll 50 pixels }]) 

update 50 pixel height of header.

regarding visibility

there few great libraries , directives checking visibility of element - try https://github.com/thenikso/angular-inview can specify whether want enable action when top, bottom or none of div visible.

note posistioning first div correctly on page prevent scroll being necessary seen in plunkr.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -