轻量级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
轻量级Modal模态框插件cta.js的更多相关文章
- modal模态框插件
用法: <!--模态框--> <div class="modal fade" id="myModal"> <div class=& ...
- Dropdown.js基于jQuery开发的轻量级下拉框插件
Dropdown.js 前言 在SPA(Single Page Application)盛行的时代,jQuery插件的轮子正在减少,由于我厂有需求而开发了这个插件.如果觉得本文对您有帮助,请给个赞,以 ...
- 第二百四十三节,Bootstrap模态框插件
Bootstrap模态框插件 学习要点: 1.基本使用 2.用法说明 本节课我们主要学习一下 Bootstrap 中的模态框插件,这是一款交互式网站非常常见的 弹窗功能插件. 一.基本使用 使用模态框 ...
- 用jQuery写了一个模态框插件
用jQuery写了一个模态框插件 大家觉得下面的框框好看么, 水印可以去掉(这个任务交给你们了(- o -)~zZ); "info"框 $("div").con ...
- 【bootstrap】modal模态框的几种打开方法+问题集锦
第一部分: 关于bootstrap中modal的使用,下面把几种自己用的打开方法展示出来 首先呢,得有个Bootstrap的页面,这里就不说了. 其次呢,得有个modal放在页面中,不管你这段代码加在 ...
- MVC中调用模态框之后导致JS失效
今天在工作中碰到一个页面调用模态框之后,页面原来的JS失效的问题,由于前台经验较少,折腾了一天... 问题描述是这样,在页面,有两个下拉列表框A和B,做了下拉列表框联动,有一个button按钮会调用模 ...
- 重置 Bootstrap modal 模态框数据
利用 Bootstrap modal 模态框弹层添加或编辑数据,第二次弹出模态框时总是记住上一次的数据值,stackoverflow 上找到个比较好的方法,就是利用 jQuery 的 clone 方法 ...
- asp.net mvc 使用bootstrap的模态框插件modal
编译器:vs2012 jquery版本:jquery-1.10.2.js bootstrap:bootstrap.js v3.0.0,包含modal插件 我们要实现一个使用模态框展示从服务器获取的数据 ...
- Bootstrap 模态框插件
一.基本使用 使用模态框的弹窗组件需要三层 div 容器元素,分别为 modal(模态声明层). dialog(窗口声明层).content(内容层).在内容层里面,还有三层,分别为 header(头 ...
随机推荐
- Tomcat之如何使用Nginx进行集群部署
目录结构: contents structure [+] 1,为什么需要集群 2,如何使用Nginx部署tomcat集群 2.1,下载Nginx 2.2,在同一台电脑上部署多个Tomcat服务器 2. ...
- 【Oracle】Oracle自定义的函数与过程
本篇主要内容如下: 6.1 引言 6.2 创建函数 6.3 存储过程 6.3.1创建过程 6.3.2调用存储过程 6.3.3 AUTHID 6.3.4 PRAGMA AUTONOMOUS_TRANSA ...
- C# 程序打包Release版本
注意:DEBUG和RELEASE的区别,DEBUG下可以直接运行,而RELEASE不一定能直接运行,这并不是表示RELEASE版本有问题,而是表示两者需要操作不同.RELEASE版本要比DEBUG版本 ...
- 【Linux】数据流重导向(后篇)
1)/dev/null 垃圾桶黑洞装置与特殊写法 想象一下,如果我知道错误信息会发生,所以要将错误信息忽略掉而不显示或储存呢? 这个时候黑洞装置 /dev/null 就很重要了!这个 /dev/nul ...
- iOS证书(.p12)和描述文件(.mobileprovision)申请
证书类型 使用场景 开发(Development)证书和描述文件 用于开发测试,在HBuilder中打包后可在真机环境通过Safari调试 发布(Distribution)证书和描述文件 用于提交Ap ...
- 第2章 Python基础-字符编码&数据类型 列表&元祖 练习题
1.创建一个空列表,命名为names,往里面添加old_driver,rain,jack,shanshan,peiqi,black_girl元素 names = ["old_driver&q ...
- FreeSWITCH收到重复的DTMF信号
一.背景 用户是运营商手机,拨打的是运营商的固话号码进入的FreeSWITCH的IVR,进入IVR语音播报后,按指定的分机号呼相关人员. 二.现象 用户反映拨打124870找不到指定人员,以前是正常的 ...
- Android studio的一些常用快捷键
Alt+回车 导入包,自动修正 Ctrl+N 查找类 Ctrl+Shift+N 查找文件 Ctrl+Alt+L 格式化代码 Ctrl+Alt+O 优化导入的类和包 Alt+Insert 生成代码(如g ...
- MongoDB联合查询 -摘自网络
1.简单手工关联 首先将结果查询出来放到一个变量里面,然后再查询 u = db.user.findOne({author:"wangwenlong"}); for(var p = ...
- nodepad++ 正则 替换
(?<k1>.*?)\=(?<k2>.*?); cookie.Add(new CookieList() { Key = "\1", Value = &quo ...