skip to Main Content

I am loading an embeddable element, but when the page loads it jumps/scrolls to the element. I’ve tried adding in a function that would scroll to the top of the page using jQuery, but to no avail.

I’ve noticed this behaviour on Chrome and Edge, however, it does not occur on FireFox. Any clues?

I expected the page to not scroll to the element. I added the jQuery function and still experience the same behaviour.

const elementConfig = {
  language: 'en-US',
  trip: {
    originAirport: "RIX",
    destinationAirport: "TLL"
  },
  placement: '',
  features: {
    showFilters: true,
    showMapLegend: true,
  }
}

function onSherpaEvent(event) {
  // Ensure that the sdk is loaded before creating the element:
  if (event.type === 'sdkLoaded') {
    $sherpa.V2.createElement('map', elementConfig).mount('#sherpa-trip-element');

  }
}

$(document).ready(function() {
  // Handler for .ready() called.
  $('html, body').animate({
    scrollTop: $('#what').offset().top
  }, 'slow');
});
<script src="https://sdk-sandbox.joinsherpa.io/widget.js?appId=sxM5NjIzNz" defer></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>

<div id="what">What</div> <br> some <br> content <br> that <br> is <br> just <br> meant <br> to <br> be <br> a <br> placeholder <br> in order <br> to see <br> if <br> this <br> scroll <br> issue <br> happens <br> here
<div id="sherpa-trip-element">sherpa-trip-element</div>

2

Answers


  1. You need to ask Sherpa. There are hundreds of scroll calls in the widget. There is no callback on mount and the document.ready is already triggered when the sherpa focuses.

    The best bet is to move the widget into an iFrame you control

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search