javascript - Scrolling to an element without ID in a window opened by window.open -


at top of page, have menu couple of items, , when click them, scroll point of in page div placed, using line of code:

$('html, body').animate({scrolltop:$(divid).position().top - 160 }, 'slow'); 

where $(divid) contains classname of div. (i using drupal possibility of adding id not there).

this works fluently, have same menu in page. when click link, navigate page div placed in, can't scroll div.

after lot of research came piece of code

$('#block-views-footer-menu-block-2 .views-row-6 a').click(function(e){     e.preventdefault();     var newwindow = window.open('/aanbod', '_self');      $(newwindow.document).ready(function(){         to_position('.field-paragraphs:nth-of-type(6)');     }); }); 

where to_position() contains first line of code in post.

however, to_position() function fires before new window loaded. way, moment to_position() function fired, '.field-paragraphs:nth-of-type(6)' not known yet, function cannot access position of it.

i don't see doing wrong, appreciated.

thanks in advance!

pass information pop-up , let scrolling you.

var newwindow = window.open('/aanbod?scrolltoposition=' + ".field-paragraphs:nth-of-type(6)", '_self'); 

now in new window, add code scroll position want scroll to

$(document).ready( function(){     var elementselector = location.search.split( "=" )[1];    var $element = $( elementselector );    $('html, body').animate({scrolltop:$element.position().top - 160 }, 'slow');  } ); 

ensure have included jquery in pop-up


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -