轻量级Modal模态框插件cta.js

今天给大家分享一款轻量级Modal模态框插件cta.js。这是一款无需使用jQuery插件,纯js编写的模态框弹出特效。效果图如下:

在线预览   源码下载

实现的代码。

html代码:

<section class="section--white" style="margin-top: 40px;">
    <div class="tile-container">
        <div class="tile" data-cta-target=".js-modal-1"></div>
        <div class="tile" data-cta-target=".js-modal-2"></div>
        <div class="tile" data-cta-target=".js-modal-3"></div>
        <div class="tile" data-cta-target=".js-modal-4"></div>
        <div class="tile" data-cta-target=".js-modal-5" style="width: 16.666%"></div>
        <div class="tile" data-cta-target=".js-modal-3"></div>
        <div class="tile" data-cta-target=".js-modal-5" style="width: 16.666%"></div>
    </div>
</section>
    <section class="section--white">
    <p>Opening modals on button clicks</p>
    <div class="btn" data-cta-target=".js-dialog" style="background: #4A90E2">Click for awesomeness</div>
</section>
    <section class="section--white">
    <p>Opening sidebars</p>
    <div class="btn" data-cta-target=".js-sidebar">Open the Sidebar</div>
</section>
    <section class="section--white">
     <script src="http://www.w2bc.com/scripts/2bc/_gg_980_90.js" type="text/javascript"></script>

</section>
    <div class="js-modal-1  modal  modal--1">
        <span class="modal-close-btn"></span>
        <h1>
            Visual Continuity</h1>
        <div class="quote-box">
            <div class="quote-box__bubble">
                Transitioning between two visual states should be clear, smooth and effortless and
                not confuse the user. A well-designed transition does the heavy lifting and enables
                the user to clearly understand where their attention should be focused.</div>
        </div>
    </div>
    <div class="js-modal-2  modal  modal--2">
        <span class="modal-close-btn"></span>
        <h1>
            Share it if you like it</h1>
    </div>
    <div class="js-modal-3  modal  modal--3">
        <span class="modal-close-btn"></span>
        <h1>
            Customary cat!</h1>
        <img src="img/cat.jpg" width="300" alt="">
        <p>
            You found me :)</p>
    </div>
    <div class="js-modal-4  modal  modal--4">
        <span class="modal-close-btn"></span>
        <h1>
            Hierarchical timing</h1>
        <div class="quote-box">
            <div class="quote-box__bubble">
                When building a transition, consider the order and timing of the elements‘ movement.
                Ensure that motion supports the information hierarchy, conveying what content is
                most important by creating a path for the eye to follow.</div>
        </div>
    </div>
    <div class="js-modal-5  modal  modal--5">
        <span class="modal-close-btn"></span>
        <h1>
            Consistent choreography</h1>
        <div class="quote-box">
            <div class="quote-box__bubble">
                A well-choreographed app also provides teachable moments. When transitioning elements
                are coordinated, the user‘s understanding of the app grows. They "get" the app;
                they don‘t feel disoriented by the animation.</div>
        </div>
    </div>
    <div class="js-dialog  modal  dialog" style="text-align: center;">
        <span class="modal-close-btn"></span>
        <h3>
            Do you think this is Awesome?</h3>
        <br>
        <a onclick="closeShowingModal(true); return;" class="btn  btn--blue">Yes</a> <a onclick="closeShowingModal(false); return;"
            class="btn  btn--blue">No</a>
    </div>
    <div class="js-sidebar  modal sidebar">
        <span class="modal-close-btn"></span>
        <div class="sidebar__block" style="height: 20%">
        </div>
        <div class="sidebar__block" style="height: 40%">
        </div>
        <div class="sidebar__block" style="height: 10%">
        </div>
    </div>

js代码:

  var closeFn;
        function closeShowingModal(liked) {
            if (liked !== undefined) {
                _gaq.push([‘_trackEvent‘, ‘ctajs‘, liked ? ‘liked‘ : ‘unliked‘]);
            }
            var showingModal = document.querySelector(‘.modal.show‘);
            if (!showingModal) return;
            showingModal.classList.remove(‘show‘);
            document.body.classList.remove(‘disable-mouse‘);
            if (closeFn) {
                closeFn();
                closeFn = null;
            }
        }
        document.addEventListener(‘click‘, function (e) {
            var target = e.target;
            if (target.dataset.ctaTarget) {
                _gaq.push([‘_trackEvent‘, ‘ctajs‘, ‘modal‘]);
                closeFn = cta(target, document.querySelector(target.dataset.ctaTarget), { relativeToWindow: true }, function showModal(modal) {
                    modal.classList.add(‘show‘);
                    document.body.classList.add(‘disable-mouse‘);
                });
            }
            else if (target.classList.contains(‘modal-close-btn‘)) {
                closeShowingModal();
            }
        });
        document.addEventListener(‘keyup‘, function (e) {
            if (e.which === 27) {
                closeShowingModal();
            }
        })

        var _gaq = _gaq || [];

via:http://www.w2bc.com/Article/36596

时间: 2024-08-25 13:56:31

轻量级Modal模态框插件cta.js的相关文章

用jQuery写了一个模态框插件

用jQuery写了一个模态框插件 大家觉得下面的框框好看么, 水印可以去掉(这个任务交给你们了(- o -)~zZ); "info"框 $("div").confrimModal("<font color=\"green\">成功! </font>", {type:"info", themeColor: "#008B8B"}, true); "alert

第二百四十三节,Bootstrap模态框插件

Bootstrap模态框插件 学习要点: 1.基本使用 2.用法说明 本节课我们主要学习一下 Bootstrap 中的模态框插件,这是一款交互式网站非常常见的 弹窗功能插件. 一.基本使用 使用模态框的弹窗组件需要三层 div 容器元素: 1分别为 modal(模态声明层). 2dialog(窗口声明层). 3content(内容层). 在内容层里面,还有三层: 1分别为 header(头 部). 2body(主体). 3footer(注脚). modal样式class类,写在声明模态框<div

第 13 章 模态框插件

学习要点: 1.基本使用 2.用法说明 主讲教师:李炎恢 本节课我们主要学习一下 Bootstrap 中的模态框插件, 这是一款交互式网站非常常见的弹窗功能插件. 一.基本使用 使用模态框的弹窗组件需要三层 div 容器元素,分别为 modal(模态声明层). dialog(窗口声明层).content(内容层).在内容层里面,还有三层,分别为 header(头部).body(主体).footer(注脚). //基本实例 <!-- 模态声明,show 表示显示 --><div class

MVC中调用模态框之后导致JS失效

今天在工作中碰到一个页面调用模态框之后,页面原来的JS失效的问题,由于前台经验较少,折腾了一天... 问题描述是这样,在页面,有两个下拉列表框A和B,做了下拉列表框联动,有一个button按钮会调用模态框,刚进入页面联动是好用的,所以联动的JS 代码没问题,点击模态框之后,JS失效. 上图是下拉列表框联动的JS 经过不懈的调试(其实就是各种瞎试)以及询问老大哥(这个才是解决之道),终于发现了问题所在: 页面刚加载进来的时候联动JS好用,是因为直接加载了JS,调用模态框之后,在success回调函

angular $modal 模态框

<!doctype html><html lang="en"><head> <meta charset="UTF-8"> <link rel="stylesheet" href="http://apps.bdimg.com/libs/bootstrap/3.2.0/css/bootstrap.min.css"> <script src="http://

bootstrap modal 模态框拖拽扩展

主管要求bootstrap modal 带有拖拽移动效果.代码如下: JS 1 // bootstrap 模态框窗口 移动扩展, 在bootstrap 初始化后 调用 2 var btModalMoveEx = function () { 3 function moveEx($this) { 4 var $head = $this.find(".modal-header"), $dialog = $this.find(".modal-dialog"); 5 var

bootstrap下modal模态框中webuploader控件按钮异常(无法点击)问题解决办法【转】

http://bbs.csdn.net/topics/391917552 具体如下:   $(function () {         var _$modal = $('#MyModal');         _$modal.css('display', 'block');         _$modal.addClass("webuploader-element-invisible");         var uploader = WebUploader.create(...);

Bootstrap 模态框插件

一.基本使用 使用模态框的弹窗组件需要三层 div 容器元素,分别为 modal(模态声明层). dialog(窗口声明层).content(内容层).在内容层里面,还有三层,分别为 header(头 部).body(主体).footer(注脚). //基本实例 <!-- 模态声明,show 表示显示 --> <div class="modal show" tabindex="-1"> <!-- 窗口声明 --> <div

bootstrap弹出层Modal 模态框

bootstrap中的模态框(modal),不同于Tooltips,模态框以弹出对话框的形式出现,具有最小和最实用的功能集. 务必将模态框的 HTML 代码放在文档的最高层级内(也就是说,尽量作为 body 标签的直接子元素),以避免其他组件影响模态框的展现或功能. 默认的modal示例: [html] view plain copy <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charse