页面元素加载时出现意外的页面滚动

huangapple go评论67阅读模式
英文:

Unexpected page scroll when element loads

问题

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 behavior 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 behavior.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->
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');
});

<!-- language: lang-html -->
<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>

<!-- end snippet -->
英文:

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.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

const elementConfig = {
  language: &#39;en-US&#39;,
  trip: {
    originAirport: &quot;RIX&quot;,
    destinationAirport: &quot;TLL&quot;
  },
  placement: &#39;&#39;,
  features: {
    showFilters: true,
    showMapLegend: true,
  }
}

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

  }
}

$(document).ready(function() {
  // Handler for .ready() called.
  $(&#39;html, body&#39;).animate({
    scrollTop: $(&#39;#what&#39;).offset().top
  }, &#39;slow&#39;);
});

<!-- language: lang-html -->

&lt;script src=&quot;https://sdk-sandbox.joinsherpa.io/widget.js?appId=sxM5NjIzNz&quot; defer&gt;&lt;/script&gt;
&lt;script src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js&quot;&gt;&lt;/script&gt;

&lt;div id=&quot;what&quot;&gt;What&lt;/div&gt; &lt;br&gt; some &lt;br&gt; content &lt;br&gt; that &lt;br&gt; is &lt;br&gt; just &lt;br&gt; meant &lt;br&gt; to &lt;br&gt; be &lt;br&gt; a &lt;br&gt; placeholder &lt;br&gt; in order &lt;br&gt; to see &lt;br&gt; if &lt;br&gt; this &lt;br&gt; scroll &lt;br&gt; issue &lt;br&gt; happens &lt;br&gt; here
&lt;div id=&quot;sherpa-trip-element&quot;&gt;sherpa-trip-element&lt;/div&gt;

<!-- end snippet -->

答案1

得分: 0

你需要询问Sherpa。小部件中有数百个滚动调用。在挂载时没有回调,当Sherpa聚焦时文档已经准备就绪。最好的方法是将小部件移到你可以控制的iFrame中。

英文:

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

huangapple
  • 本文由 发表于 2023年2月6日 14:48:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/75358137.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定