轻量级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(头 ...
随机推荐
- 【Android】Android如何实现手机震动
实现手机震动其实很简单,手机震动使用是Vibrator类,然后震动也是需要权限的,在使用之前在AndroidManifest.xml文件中添加 <uses-permission android: ...
- k近邻算法-java实现
最近在看<机器学习实战>这本书,因为自己本身很想深入的了解机器学习算法,加之想学python,就在朋友的推荐之下选择了这本书进行学习. 一 . K-近邻算法(KNN)概述 最简单最初级的分 ...
- Runway for Mac(UML 流程图绘图工具)破解版安装
1.软件简介 Runway 是 macOS 系统上一款强大实用的软件开发工具,Runway for Mac 是一个界面简单功能强大的UML设计师.此外,Runway for Mac 带给你所有你 ...
- numpy、scipy、matplotlib、OpenCV安装及问题解决
1 numpy 概述 numpy是Numerical Python的缩写,释义为数值的Python numpy弥补了作为通用编程语言的Python在数值计算方面能力弱.速度慢的不足(numpy的底层是 ...
- mysql用户权限管理的问题
为了保证数据库安全,建立了若干个只能select的用户,但在权限授权的时候出现了不能连接的问题, 一个个尝试了一下,需要将 : 管理 -> SUPER项勾选才行(使用phpmyadmin),上 ...
- asp.net 浏览器下载文件的四种方式
// 方法一:TransmitFile实现下载 protected void Button1_Click(object sender, EventArgs e) { Response.ContentT ...
- 开关电源电路中变压器次级输出绕组RC串联并接在二极管两端的作用
二极管反向恢复时会产生浪涌电压,这里RC主要是吸收二极管D1产生的浪涌电压,防止二极管损坏. 寄生电容:寄生电容一般是指电感,电阻,芯片引脚等在高频情况下表现出来的电容特性.实际上,一个电阻等效于一个 ...
- python 视频 图像帧提取
import cv2 vidcap = cv2.VideoCapture('005.avi') success,image = vidcap.read() count = 0 success = Tr ...
- Windows平台JDK安装
原文链接:http://android.eoe.cn/topic/android_sdk 下载Java的开发包JDK JDK有好几个类型版本,我们只需要选择Java SE类型的版本就行了.进入网页:h ...
- [hihoCoder] 第四十八周: 拓扑排序·二
题目1 : 拓扑排序·二 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho所在学校的校园网被黑客入侵并投放了病毒.这事在校内BBS上立刻引起了大家的讨论,当 ...