Amp-sidebar: Is it absolutely necessary to be a child of the body? What for?

Why <amp-sidebar>HAVE to be a direct descendant of the body?

I am in a situation where, in terms of code structure, it would be much easier to include <amp-sidebar>in <div>. I want it to behave exactly the same as <amp-sidebar>, but I just don't have an easy way to place an element as a direct child <body>.

I was particularly confused when I saw that this amp-by-example page does not pass the AMP validator.

Can someone please light me up? I was thinking about opening a problem on github, but I'm not sure if there is an error.

+4
source share
2 answers

AMP, , <amp-sidebar> <body>, Safari position:fixed. .

+2

, html . :

function fixAmpSidebars(strHtml) {
    let sidebarBegin = 0, sidebarEnd = 0
    const sidebars = []
    do {
        sidebarBegin = strHtml.indexOf('<amp-sidebar', sidebarBegin)
        if (sidebarBegin !== -1) {
            sidebarEnd = strHtml.indexOf('</amp-sidebar>', sidebarBegin) + 14
            sidebars.push(strHtml.slice(sidebarBegin, sidebarEnd))
            strHtml = strHtml.slice(0, sidebarBegin) + strHtml.slice(sidebarEnd)
        }
    } while (sidebarBegin !== -1)
    if (sidebars.length) {
        strHtml = strHtml + sidebars.join('')
    }

    return strHtml
}
0

Source: https://habr.com/ru/post/1656714/


All Articles