今天给大家分享一款轻量级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

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

  1. modal模态框插件

    用法: <!--模态框--> <div class="modal fade" id="myModal"> <div class=& ...

  2. Dropdown.js基于jQuery开发的轻量级下拉框插件

    Dropdown.js 前言 在SPA(Single Page Application)盛行的时代,jQuery插件的轮子正在减少,由于我厂有需求而开发了这个插件.如果觉得本文对您有帮助,请给个赞,以 ...

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

    Bootstrap模态框插件 学习要点: 1.基本使用 2.用法说明 本节课我们主要学习一下 Bootstrap 中的模态框插件,这是一款交互式网站非常常见的 弹窗功能插件. 一.基本使用 使用模态框 ...

  4. 用jQuery写了一个模态框插件

    用jQuery写了一个模态框插件 大家觉得下面的框框好看么, 水印可以去掉(这个任务交给你们了(- o -)~zZ); "info"框 $("div").con ...

  5. 【bootstrap】modal模态框的几种打开方法+问题集锦

    第一部分: 关于bootstrap中modal的使用,下面把几种自己用的打开方法展示出来 首先呢,得有个Bootstrap的页面,这里就不说了. 其次呢,得有个modal放在页面中,不管你这段代码加在 ...

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

    今天在工作中碰到一个页面调用模态框之后,页面原来的JS失效的问题,由于前台经验较少,折腾了一天... 问题描述是这样,在页面,有两个下拉列表框A和B,做了下拉列表框联动,有一个button按钮会调用模 ...

  7. 重置 Bootstrap modal 模态框数据

    利用 Bootstrap modal 模态框弹层添加或编辑数据,第二次弹出模态框时总是记住上一次的数据值,stackoverflow 上找到个比较好的方法,就是利用 jQuery 的 clone 方法 ...

  8. asp.net mvc 使用bootstrap的模态框插件modal

    编译器:vs2012 jquery版本:jquery-1.10.2.js bootstrap:bootstrap.js v3.0.0,包含modal插件 我们要实现一个使用模态框展示从服务器获取的数据 ...

  9. Bootstrap 模态框插件

    一.基本使用 使用模态框的弹窗组件需要三层 div 容器元素,分别为 modal(模态声明层). dialog(窗口声明层).content(内容层).在内容层里面,还有三层,分别为 header(头 ...

随机推荐

  1. kubelet源码分析(version: git tag 1.7.6)

    一.概述 kubelet源码入口:cmd/kubelet/kubelet.go main() cmd/kubelet/app 包中的Run函数: 查看先参数,kubelet.KubeletDeps t ...

  2. 富文本编辑器 CKeditor 配置使用

    作者:Tyler Ning出处:http://www.cnblogs.com/tylerdonet/本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连 ...

  3. redis常用性能分析命令

    一.连接 src/redis-cli -h 10.20.137.141 -p 6379 >auth 123456789 src/redis-cli -h 10.20.137.141 -p 637 ...

  4. MySQL -- 全文检索(布尔全文检索)

    modifier的值为in boolean mode的时候,可以使用布尔全文检索.在布尔全文检索中,有些字符在检索字符串的开头或结尾会有特殊含义.在下面的示例中,+和-操作符表明在匹配的时候,单词必须 ...

  5. [Warning] TIMESTAMP with implicit DEFAULT value is deprecated

    启动mysql时,报如下警告信息: [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explic ...

  6. Asp.net2.0之自定义控件ImageButton

    控件模仿winform中的button,可以支持图片和文字.可以选择执行服务器端程序还是客户端程序,还有一些简单的设置. 不足的是不支持样式,下次希望可以写一个工具条. 以下就是代码 以下为引用的内容 ...

  7. mysql 5.5数据库主从配置步骤详解

    上次给大家介绍了mysql 5.1主从搭建配置教程,这次我们来实现mysql 5.5的主从复制,其实大体上配置是差不多的,只有点细微的差别. 系统:centos 5.x 需要的软件包:mysql-5. ...

  8. [转]同步对象Event的用法

    同步对象Event的用法  首先介绍CreateEvent是创建windows事件的意思,作用主要用在判断线程退出,线程锁定方面.  CreateEvent函数功能描述:创建或打开一个命名的或无名的事 ...

  9. appium 重新启动apk

    在旧版本的appium,重新启动apk,调用startActivity方法可以随意启动一个app,并传入一个package name 和启动activity name的名称.语句如下: driver. ...

  10. ARM:移动GPU往PC GPU效能迈进

    行动装置的热潮持续不退,各大手机制造商除了想尽办法推出外型酷炫的行动装置设备来吸引消费者的目光之外,更在行动应用处理器玩起多核心的「核」战争,无非是希望能够带给消费者更优异的效能新体验.然而,随着消费 ...