今天给大家分享一款轻量级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. sql 2005出现错误:数据库 'Twitter' 的事务日志已满。若要查明无法重用日志中的空间的原因,请参阅 sys.databases 中的 log_reuse_wait_desc 列。

    --先备份数据库 --截断事务日志 backup   log   Twitter with   no_loggo --收缩数据库 dbcc   shrinkdatabase(Twitter) go O ...

  2. iOS11新特性之LargeTitle

    UI风格 在iOS 11中,系统APP使用了这种UI风格.这种风格最明显的变化就是使用了iOS 11的新特性--Large Title和新的SearchController. Demo GitHub: ...

  3. 基于matplotlib的数据可视化 - 三维曲面图gca

    1 语法 ax = plt.gca(projection='3d')ax.plot_surface(x,y,z,rstride=行步距,cstride=列步距,cmap=颜色映射) gca(**kwa ...

  4. 【转】我的第一次和最后一次 Hackathon 经历

    我的第一次和最后一次 Hackathon 经历 在旧金山地区经常有一些叫做“Hackathon”的活动,吸引挺多人参加.我一直听说这个名字,可是一直不知道它到底是什么.我从来对竞赛式的活动不感兴趣,我 ...

  5. Python把同一个对象循环赋值给另外一个变量

    Python把同一个对象循环赋值给另外一个变量,修改一个对象,其他对象也修改了 >>> row=['_'] * 3 >>> board = [] >>& ...

  6. php分享三十二:php调试工具

    一:phpdbg http://phpdbg.com/

  7. Android开发系列(十五):【Android小游戏成语连连看】第一篇

            学了一个多月安卓.由于暑假的时候要给朋友说写个小游戏.并且也想检測下自己的能力,所以说从7号開始就着手写这个小游戏了,前前后后带上课到今天总算是写完了,可是写的这个小游戏还是有非常多问 ...

  8. jmeter经验---java 追加写入代码一例

    最近最项目参数化的时候用到,场景是这样的,需要测试A和B两个接口,其中B接口传入的参数必须是传递给A接口过的,所以整理一个思路就是: 1. 正常调用A接口,但是将传递给A接口的参数保存到文本里,此处要 ...

  9. Android log 日志分析

    一. Log 日志中 Bug 类型 程序异常强制关闭: Force Close ,Fatal 程序无响应: Application Not Response , ANR(应用无响应).一般是主线程超时 ...

  10. Atitit 项目源码的架构,框架,配置与环境说明模板 规范 标准化

    Atitit 项目源码的架构,框架,配置与环境说明模板  规范 标准化 版本1.0 作者 艾龙 attilax 1. 概述:核心业务: 1 1.1. 功能文档路径 /palmWin/src/docum ...