问题描述:

I have used the offcanvas push menu on my website. I want the menu to be opened on certain pages of my site on page load, but the toggle still wok for the viewer to close it / open again if they wish.

How would i set the menu to be open only on certain pages? (pages which all use the same template so I can add custom js to this template only).

I have been looking at the methods and venets in the documentation,but can't work out how to do what i need.

I have tried the 'show' method in just the page template I want the menu to load open on:

<script>

$(function () { $('.navmenu').offcanvas('show'); });

</script>

it works by loading page with the menu open; but laid OVER the 'canvas' (body) - rather than pushing the body off canvas as it does usually. Other than adding this extra jquery to my page i have used the same code as in Jasny's example.

See the fiddle

Many thanks!

网友答案:

The data-* attributes of the button are only used when clicking the button. This is kind of a misdesign of the off canvas plugin.

In this case you shouldn't use the data attributes at all, initialize it in JavaScript instead.

<script>
  $(function () {
    $('.navmenu').offcanvas({
      toggle: "offcanvas",
      target: ".navmenu",
      canvas: "body"
    }).offcanvas('show');
  });
</script>
相关阅读:
Top