Amaze UI 2.4

JavaScript

Amaze UI styled jQuery plugins and utils.

OffCanvas


Create a smooth off-canvas sidebar that slides in and out of the page. See more details in menu widget(Example 1, Example 2).

Examples

The Off-canvas component consists of an overlay and an off-canvas bar. Add data-am-offcanvas attribute to the overlay, and use specified HTML stucture for off-canvas bar.

Default Style

Show offcanvas

我不愿让你一个人
承受这世界的残忍
我不愿眼泪陪你到 永恒

<!-- Link Trigger, whose href attribute is the ID of target element -->
<a href="#doc-oc-demo1" data-am-offcanvas>Show offcanvas</a>

<!-- Offcanvas contents -->
<div id="doc-oc-demo1" class="am-offcanvas">
  <div class="am-offcanvas-bar">
    <div class="am-offcanvas-content">
      <p>
        我不愿让你一个人 <br/>
        承受这世界的残忍 <br/>
        我不愿眼泪陪你到 永恒
      </p>
    </div>
  </div>
</div>

Push Effect

Set effect: 'push'.

我不愿让你一个人
承受这世界的残忍
我不愿眼泪陪你到 永恒

<!-- Button trigger. Need to specify the target -->
<button class="am-btn am-btn-primary" data-am-offcanvas="{target: '#doc-oc-demo2', effect: 'push'}">Click to show the offcanvas</button>

<!-- Offcanvas contents -->
<div id="doc-oc-demo2" class="am-offcanvas">
  <div class="am-offcanvas-bar">
    <div class="am-offcanvas-content">
      <p>
        我不愿让你一个人 <br/>
        承受这世界的残忍 <br/>
        我不愿眼泪陪你到 永恒
      </p>
    </div>
  </div>
</div>

Right Offcanvas

Offcanvas is on the left by default. Add the .am-offcanvas-bar-flip class to offcanvas content to move it to the right.

我不愿让你一个人
承受这世界的残忍
我不愿眼泪陪你到 永恒

网易音乐

<!-- Button trigger. Need to specify the target -->
<button class="am-btn am-btn-success" data-am-offcanvas="{target: '#doc-oc-demo3'}">右侧显示侧边栏</button>

<!-- Offcanvas contents -->
<div id="doc-oc-demo3" class="am-offcanvas">
  <div class="am-offcanvas-bar am-offcanvas-bar-flip">
    <div class="am-offcanvas-content">
      <p>
        我不愿让你一个人 <br/>
        承受这世界的残忍 <br/>
        我不愿眼泪陪你到 永恒 <br/>
      </p>
      <p><a href="http://music.163.com/#/song?id=385554" target="_blank">网易音乐</a>      </p>
    </div>
  </div>
</div>
<div id="my-id" class="am-offcanvas">
    <div class="am-offcanvas-bar am-offcanvas-bar-flip">...</div>
</div>

Usage

First, create your offcanvas content using following structure:

<div id="your-id" class="am-offcanvas">
  <div class="am-offcanvas-bar">
    <!-- Your content -->
  </div>
</div>

Using Data API

Add data-am-offcanvas attribute to the overlay element:

  • If this element is an <a>, set href to be the ID of offcanvas:href="#your-id";
  • Otherwise, specify the ID of offcanvas in data-am-offcanvas :
<button data-am-offcanvas="{target: '#your-id'}"></button>
AttributeDescription
{target: '#your-id'}Specify the offcanvas. If overlay is an a element, specify it in href.
{effect: 'push'}Offcanvas animation. include overlay | push. Default value is overlay

Using JS

Use Javascript to control the Offcanvas.

$('#my-offcanvas').offCanvas(options);

Attension: The #my-offcanvas here points directly to the offcanvas instead of the overlay.

Options

  • options.effect. Available options include overlay | push. Default value is overlay.
$('#my-offcanvas').offCanvas({effect: 'push'});

Set through $().offCanvas(options).

Methods

  • $().offCanvas(options) - Set the offcanvas attribute and show it.
  • $().offCanvas('open') - Show the offcanvas.
  • $().offCanvas('close') - Hide the offcanvas.

Events

EventDescription
open.offcanvas.amuiFired immediately when offcanvas is opened.
close.offcanvas.amuiFired immediately when offcanvas is closed.

JS Control Examples

The following example shows how to use JS to open/close the offcanvas. The close button can't be directly clicked when offcanvas is opened. Please use following code to simulate the click event:

$('[data-rel="close"]').click();

你那张略带着
一点点颓废的脸孔
轻薄的嘴唇
含着一千个谎言

<!-- Offcanvas contents -->
<div id="my-offcanvas" class="am-offcanvas">
  <div class="am-offcanvas-bar">
    <div class="am-offcanvas-content">
      <p>
        你那张略带着 <br/>
        一点点颓废的脸孔 <br/>
        轻薄的嘴唇 <br/>
        含着一千个谎言
      </p>
    </div>
  </div>
</div>

<button class="am-btn am-btn-primary doc-oc-js" data-rel="open">Open the offcanvas</button>
<button class="am-btn am-btn-primary doc-oc-js" data-rel="close">Close the offcanvas</button>

<script>
  $(function() {
    var id = '#my-offcanvas';
    var $myOc = $(id);
    $('.doc-oc-js').on('click', function() {
      $myOc.offCanvas($(this).data('rel'));
    });

    $myOc.on('open.offcanvas.amui', function() {
      console.log(id + ' is opened.');
    }).on('close.offcanvas.amui', function() {
      console.log(id + ' is closed.');
    });
  });
</script>
侧栏导航
Amaze UI 微信
在微信上关注我们