问题
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