Google AMP script conflicts with jquery window.scroll

梦想的初衷 提交于 2020-02-02 05:42:24

问题


I'm trying to follow the AMP guidelines suggested by Google (ampproject.org) but as soon as I add their js script, the jQuery scroll stops working

Does anybody knows why and how to fix it?


回答1:


The script tag is prohibited in AMP HTML unless:

  • The type is application/ld+json
  • It is the mandatory script tag to load the AMP runtime
  • It is a tag to load extended components

https://github.com/ampproject/amphtml/blob/master/spec/amp-html-format.md#html-tags

A list of available extensions, such as amp-carousel, can be found here.

You can also use custom elements and web components according to this page.

"AMP components may have JavaScript under the hood, but it is coordinated with other AMP components, so its composition into the page doesn’t cause performance degradation."




回答2:


The only way to include JQuery scroll is to pull it in via an AMP-IFRAME tag. But that will only give you access to it within the context of the amp-iframe so most likely that will not help you. What are you trying to accomplish with the JQuery scroll? AMP pages are meant to be simple and for displaying information very quickly. Best examples for the use of AMP pages are news sites. If you open CHROME debugger and click on the mobile view icon and then do a search for say "Trump", you'll see the carousel of AMP pages at the top. You'll notice that they are all simple news stories. Nothing to fancy.

Do you have an example of what you are trying to do that we can look at?



来源:https://stackoverflow.com/questions/35209559/google-amp-script-conflicts-with-jquery-window-scroll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!