JavaScript Go to a specific anchor after page resizes (height change only)

I have a one-page website with several anchors (signifying div positions). After the page is resized (change in height only), I want to refresh the page. Then I want to scroll to the anchor the page was previously at, making the window.top position equal to the anchor position. I have javascript for the resize and refresh portion of this (below), but I'm at a loss regarding the scroll portion. Any ideas? How would I check which div the page was on before resizing? "#markerAbout" is one of the anchors.

var height = $(window).height();
var resizeTimer;
$(window).resize(function(){
   if($(this).height() != height){
      height = $(this).height();
      window.location.reload();
      //$(window).scrollTop()=$('#markerAbout').offset().top;   
   }
});
Answer:1

You can find out which of your elements are currently visible on the view port by following the advice in this question: How to tell if a DOM element is visible in the current viewport?

You will have to do this on each element in the order you expect them to appear until you find one that is visible. That should be the current element at the top of the viewport.

function elementInViewport2(el) {
  var top = el.offsetTop;
  var left = el.offsetLeft;
  var width = el.offsetWidth;
  var height = el.offsetHeight;

  while(el.offsetParent) {
    el = el.offsetParent;
    top += el.offsetTop;
    left += el.offsetLeft;
  }

  return (
    top < (window.pageYOffset + window.innerHeight) &&
    left < (window.pageXOffset + window.innerWidth) &&
    (top + height) > window.pageYOffset &&
    (left + width) > window.pageXOffset
  );
}

Once you know which of your divs are showing and which are not, you can choose which one you want to scroll too.

Once you know which div to scroll to for example Div1, you can call scrollIntoView() on that element.

Div1.scrollIntoView();
Answer:2

I need this input informs when the user does not use a valid email address. takes the form gets red border or a message appears (a hover) next to the field HTML <body ng-controller="...

I need this input informs when the user does not use a valid email address. takes the form gets red border or a message appears (a hover) next to the field HTML <body ng-controller="...

  1. validating email address with regex
  2. validating email address with regex hackerrank
  3. validating email address with regex python
  4. validating email address with regex java
  5. validating email address with regex hackerrank java
  6. validating email address with regex c++
  7. validating email address with regex leetcode
  8. validating email address python
  9. validating email addresses with a filter hackerrank solution
  10. validating email address javascript
  11. validating email addresses with a filter
  12. validating email address in java
  13. validating email address in html
  14. validating email address in php
  15. validating email address c++
  16. validating email address in excel
  17. validating email address with regex hackerrank solution
  18. validating email address with regex hackerrank javascript

I have done a very long and tedious way of showing details for each option from the select list. I do understand this should not be the way as imagining having to do for hundreds of options. It is ...

I have done a very long and tedious way of showing details for each option from the select list. I do understand this should not be the way as imagining having to do for hundreds of options. It is ...

  1. display fields from table
  2. display fields in lightning component
  3. display fields in report filter area
  4. display fields in word
  5. display fields in mongodb
  6. display fields in visualforce page
  7. display fields in html
  8. display fields in splunk
  9. display fields in table sql
  10. display fields in powerapps
  11. display fields in sql
  12. display fields of custom post type
  13. display fields in jira
  14. display fields in tableau
  15. display fields in cobol
  16. display fields in access
  17. display fields in foxpro
  18. display fields inline
  19. form display field
  20. display fields in arcmap

I have some element like : <button ng-click="weirdFunction()">Pretty Button</button> And function in controller : $scope.weirdFunction = function(element) { console.log(element); } in ...

I have some element like : <button ng-click="weirdFunction()">Pretty Button</button> And function in controller : $scope.weirdFunction = function(element) { console.log(element); } in ...

  1. element with click event
  2. element click intercepted
  3. element click intercepted selenium
  4. element click intercepted exception
  5. element click
  6. element click javascript
  7. element click intercepted exception selenium
  8. element click intercepted protractor
  9. element click intercepted selenium python
  10. element click intercepted selenium java
  11. element click intercepted selenium c#
  12. element click jquery
  13. element click intercepted error in selenium
  14. element click js
  15. element clickable selenium
  16. element click intercepted python
  17. element click intercepted exception in selenium java
  18. element click web scraper
  19. element.click not working
  20. element click intercepted exception in selenium webdriver

I am working on a plugin for an internal tool that keeps track of how long it takes to work on specific tasks. I am presenting a visual reference of the time its taken but using the timestamps in the ...

I am working on a plugin for an internal tool that keeps track of how long it takes to work on specific tasks. I am presenting a visual reference of the time its taken but using the timestamps in the ...