0

A menu included in multiple pages with an iframe has the following rule: .header_area.navbar_fixed .main_menu {transform: translateY(70px);} . It works perfectly when the menu is put direcly on the page (not through iframe). But when loaded through an iframe, the transform: translate rule of the menu doesn’t work. Here is the demo: http://project-smac.orgfree.com . And this is how the menu behaves when menu is directly on the page (not through iframe): http://project-smac.orgfree.com/en/projects-for-future-humanity.html . Can anybody help me please?

I have tried changing the following rule: .header_area {position:absolute;} to position: fixed; but it didn’t do the trick. I have searched in Google but haven’t found anything that can help me. I also tried changing .header_area.navbar_fixed .main_menu {position: fixed;} to position: absolute (following some advice I found in Google) and it didn't do the trick either.

This is the html for the menu:

<header class="header_area">
    <div class="main_menu">
        <div class="container">
            <nav class="navbar navbar-expand-lg navbar-light">
                <div class="container">


                    <!-- Collect the nav links, forms, and other content for toggling -->
                    <div class="collapse navbar-collapse offset" id="navbarSupportedContent">
                        <ul class="nav navbar-nav menu_nav ml-auto">
                            <li class="nav-item"><a class="nav-link mn_home" href="">Home</a></li>
                            <li class="nav-item"><a class="nav-link mn_projects" href="">Projects</a></li>
                            <li class="nav-item"><a class="nav-link mn_about" href="">About</a></li>
                            <li class="nav-item"><a class="nav-link mn_communiques" href="">Communiqu&eacute;s</a></li>
                            <li class="nav-item"><a class="nav-link mn_donate" href="">Donate</a></li>
                            <li class="nav-item submenu dropdown">
                                <a href="" class="nav-link dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Languages</a>
                                <ul class="dropdown-menu">
                                    <li class="nav-item  mn_english"><a class="nav-link" href="">English</a></li>
                                    <li class="nav-item"><a class="nav-link" href="">Spanish</a></li>
                                </ul>
                            </li>
                            <li class="nav-item"><a class="nav-link mn_contact" href="">Contact</a></li>
                        </ul>
                    </div>
                </div>
            </nav>
        </div>
    </div>
</header>

Menu is loaded through an include with iframe:

<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Documento sin título</title>
    </head>

    <body>
    <iframe src="/en/inc/menu.html" onload="this.before((this.contentDocument.body||this.contentDocument).children[0]);this.remove()"></iframe><!-- Include code to load navigation menu - - - - - - - - - - - - - - - - - - - - - - - -->

    </body>
</html>

And this is the css that doesn't work when menu is loaded through iframe (the transform: translateY:

.header_area.navbar_fixed .main_menu {
    position: fixed;
    width: 100%;
    top: -70px;
    left: 0;
    right: 0;
    background: #222222;
    transform: translateY(70px);
    transition: transform 500ms ease, background 500ms ease;
    -webkit-transition: transform 500ms ease, background 500ms ease;
    box-shadow: 0px 3px 16px 0px rgba(0, 0, 0, 0.1); 
    }

The expected behavior is that the menu should go up with the page (as shown in: http://project-smac.orgfree.com/en/projects-for-future-humanity.html ) and then come back as position: fixed; to the top of the page, but it just goes up and doesn't come back.

  • Why, oh WHY use an iFrame? – mplungjan Aug 25 '19 at 05:00
  • I tried with JS and menu displays the same wrong behavior: https://stackoverflow.com/questions/57640452/jquery-load-function-doesn-t-work-because-file-loaded-contains-small-js?noredirect=1#comment101737507_57640452 – Ramon D Marin Aug 25 '19 at 15:17
  • Actually I found out that the iframe inlcude is not working in mobile, so I decided to use JS for the include and ask a new question: https://stackoverflow.com/questions/57896907/rule-transform-translatey-in-menu-doesn-t-work-properly-when-menu-is-loaded-i – Ramon D Marin Sep 11 '19 at 21:16
  • So feel free to delete this question – mplungjan Sep 12 '19 at 01:50
  • The problem occurs both with I frame and JS. I imagine both questions can be useful to future users. I'm receiving help somewhere else, so I'll bring the answer here – Ramon D Marin Sep 12 '19 at 02:54
  • Ok. I strongly recommend not to use an ifrane – mplungjan Sep 12 '19 at 04:04

0 Answers0