css3+JS实现幻灯片轮播图
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title></title>
- <style>
- *{
- margin: 0;
- padding: 0;
- -webkit-touch-callout: none;
- -webkit-user-select: none;
- -khtml-user-select: none;
- -moz-user-select: none;
- -ms-user-select: none;
- user-select: none;
- }
- .clearfix:after{
- clear: both;
- }
- .clearfix:after,.clearfix:before{
- content: "";
- display: table;
- }
- .slide_view{
- width: 600px;
- height: 200px;
- overflow: hidden;
- margin: 40px auto;
- position: relative;
- }
- ul{
- width: 600px;
- height: 100%;
- }
- li{
- position: absolute;
- width: 600px;
- height:100%;
- opacity: 0;
- }
- li.active{
- opacity: 1;
- }
- .hor-slide-ani .next-out
- {
- animation: hor-slide-next-out .8s forwards cubic-bezier(0.7, 0, 0.3, 1);
- }
- .hor-slide-ani .next-in{
- animation: hor-slide-next-in .8s forwards cubic-bezier(0.7, 0, 0.3, 1);
- }
- .hor-slide-ani .prev-out
- {
- animation: hor-slide-prev-out .8s forwards cubic-bezier(0.7, 0, 0.3, 1);
- }
- .hor-slide-ani .prev-in{
- animation: hor-slide-prev-in .8s forwards cubic-bezier(0.7, 0, 0.3, 1);
- }
- @keyframes hor-slide-next-out{
- from{
- opacity: 1;
- }
- to{
- opacity: 1;
- transform: translateX(100%);
- }
- }
- @keyframes hor-slide-next-in{
- from{
- opacity: 1;
- transform: translateX(-100%);
- }
- to{
- opacity: 1;
- transform: translateX(0);
- }
- }
- @keyframes hor-slide-prev-out{
- from{
- opacity: 1;
- }
- to{
- opacity: 1;
- transform: translateX(-100%);
- }
- }
- @keyframes hor-slide-prev-in{
- from{
- opacity: 1;
- transform: translateX(100%);
- }
- to{
- opacity: 1;
- transform: translateX(0);
- }
- }
- .prev{
- position: absolute;
- left: 10px;
- top: 40%;
- display: block;
- padding: 10px;
- text-align: center;
- width: 20px;
- height: 20px;
- border-radius: 100%;
- background: rgba(0,0,0,.4);
- color: white;
- font-size: 22px;
- line-height: 22px;
- }
- .next{
- position: absolute;
- right: 10px;
- top: 40%;
- display: block;
- padding: 10px;
- text-align: center;
- width: 20px;
- height: 20px;
- border-radius: 100%;
- background: rgba(0,0,0,.4);
- color: white;
- font-size: 22px;
- line-height: 22px;
- }
- </style>
- </head>
- <body>
- <div class="slide_view">
- <ul class="slides clearfix hor-slide-ani" style="position: relative;">
- <li class="active" style="background: salmon;">1</li>
- <li style="background: darkcyan;">2</li>
- <li style="background: seagreen;">3</li>
- <li style="background: sandybrown;">4</li>
- </ul>
- <div class="control">
- <span class="prev">←</span>
- <span class="next">→</span>
- </div>
- </div>
- </body>
- <script type="text/javascript" src="js/jquery-2.1.4.min.js" ></script>
- <script>
- var aniName = (function(el) {
- var animations = {
- animation: 'animationend',
- OAnimation: 'oAnimationEnd',
- MozAnimation: 'mozAnimationEnd',
- WebkitAnimation: 'webkitAnimationEnd',
- };
- for (var t in animations) {
- if (el.style[t] !== undefined) {
- return animations[t];
- }
- }
- return false;
- })(document.createElement('div'));
- var aniEndCallback=function($ele,endCall){
- if(aniName && typeof endCall == 'function'){
- var called=false;
- //在每次transitionEnd的事件后执行该函数
- var callback = function(){
- if (!called){
- called=true;
- endCall($ele);
- }
- };
- $ele[0].addEventListener(aniName,function(){
- callback();
- //通过setTimeout来补救windowphone中不触发事件的问题
- setTimeout(callback,200);
- },false);
- }else{
- endCall($ele);
- }
- };
- $(function(){
- var aniStatus = false;
- $('.next').click(function(){
- if(aniStatus){return};
- aniStatus = true;
- var $slides = $('.slides').children()
- , slideCount = $slides.length
- , $active = $('.active')
- , curActiveIndex = $('.active').index()
- , nextActiveIndex = curActiveIndex -1;
- if(curActiveIndex == 0){
- nextActiveIndex = slideCount-1;
- }
- $slides.eq(curActiveIndex).addClass('next-out');
- $slides.eq(nextActiveIndex).addClass('next-in');
- aniEndCallback($active,function($ele){
- aniStatus = false;
- $active.removeClass('next-out active');
- $slides.eq(nextActiveIndex).removeClass('next-in').addClass('active');
- });
- });
- $('.prev').click(function(){
- if(aniStatus){return;}//不在动画状态,才能执行
- aniStatus= true;
- var $slides = $('.slides').children()
- , slideCount = $slides.length
- , $active = $('.active')
- , curActiveIndex = $('.active').index()
- , nextActiveIndex = curActiveIndex + 1;
- if(curActiveIndex == slideCount-1){
- nextActiveIndex = 0;
- }
- $slides.eq(curActiveIndex).addClass('prev-out');
- $slides.eq(nextActiveIndex).addClass('prev-in');
- aniEndCallback($active,function($ele){
- aniStatus = false;
- $active.removeClass('prev-out active');
- $slides.eq(nextActiveIndex).removeClass('prev-in').addClass('active');
- });
- });
- setInterval(function(){
- $('.prev').trigger('click')
- },4000);
- });
css3+JS实现幻灯片轮播图的更多相关文章
- CSS3最简洁的轮播图
<!DOCTYPE html> <html> <head> <title>CSS3最简洁的轮播图</title> <style> ...
- jQuery与原生js实现banner轮播图
jQuery与原生js实现banner轮播图: (jq需自己加载)(图片需自己加载) <!DOCTYPE html> <html> <head> <meta ...
- 原生JS实现简易轮播图
原生JS实现简易轮播图(渐变?) 最近做网页总是会用到轮播图,我就把之前写的轮播图单独拿出来吧,如果有...如果真的有人也需要也可以复制去用用啊..哈~.. window.onload = funct ...
- js原生实现轮播图效果(面向对象编程)
面向对象编程js原生实现轮播图效果 1.先看效果图 2.需要实现的功能: 自动轮播 点击左右箭头按钮无缝轮播 点击数字按钮切换图片 分析:如何实现无缝轮播? 在一个固定大小的相框里有一个ul标签,其长 ...
- css3实现3D切割轮播图案例
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- JS学习笔记--轮播图效果
希望通过自己的学习收获哪怕收获一点点,进步一点点都是值得的,加油吧!!! 本章知识点:index this for if else 下边我分享下通过老师教的方式写的轮播图,基础知识实现: 1.css代 ...
- 原生 js 左右切换轮播图
使用方法: 可能很多人对轮播图感兴趣,下面奉上本人的 原生 js 轮播代码复制 js 到页面的最底部,样式在 css 里改,js 基本不用动,有什么不懂的可以 加本人 QQ172360937 咨询 或 ...
- photoSlider-原生js移动开发轮播图、相册滑动插件
详细内容请点击 在线预览 立即下载 使用方法: 分别引用css文件和js文件 如: <link rel="stylesheet" type="text/css& ...
- photoSlider-html5原生js移动开发轮播图-相册滑动插件
简单的移动端图片滑动切换浏览插件 分别引用css文件和js文件 如: <link rel="stylesheet" type="text/css" hre ...
随机推荐
- python字典基本操作
字典是python中五中基本数据类型之一,虽然它的赋值稍微麻烦点,但用起来真的是很方便.它用键值对来存放数据,所谓键值对,就是一个键,对应一个值,如果后面对前面的键再次赋值,第一次的值就被覆盖掉.像是 ...
- day5_configparser模块
第一种情况:# 配置文件baidu.ini和当前文件在同一级目录: import configparser conf_read = configparser.ConfigParser() conf_r ...
- 读架构漫谈&我眼中的架构师
本周是开学的第二周,读了由资深架构师王概凯 Kevin 执笔的系列专栏架构漫谈.初识这门课,懂得也不是很多,读了架构漫谈,有了一些理解. 首先作者讲述了缘起,由早期人独立自主生活到后来的集群,作者由这 ...
- 003VlookUp的使用
在Excel中,Vlookup这个函数还是挺有用的 我最近在一个场景中使用到VlookUp函数,使用场景是 我们将学生名单导入到学业上报系统的时候,发现Excel中有 79条数据但是导入成功的提示是说 ...
- <Dynamic Programming> 120 279
120. Triangle 从倒数第二行找,然后逐个遍历这个DP数组,对于每个数字,和它之后的元素比较选择较小的再加上面一行相邻位置的元素做为新的元素,然后一层一层的向上扫描 class Soluti ...
- 【转】Java代码编译过程简述
转载:https://blog.csdn.net/fuzhongmin05/article/details/54880257. 代码编译是由Javac编译器来完成,流程如下图1所示: 图1 Javac ...
- IAR环境搭建
工具下载:https://pan.baidu.com/s/1nwv0RVz 第一步:右键点击EW8051-EV-8103-Web.exe,使用管理员权限运行. 第二步:我们运行之后只要一直Next下去 ...
- Bootstrap-table实现动态合并相同行
Bootstrap-table 表格合并相同名字的列 @编写function() /** * 合并行 * @param data 原始数据(在服务端完成排序) * @param fieldName ...
- [LeetCode] 327. Count of Range Sum 区间和计数
Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive.Ra ...
- KMP 串的模式匹配 (25分)
给定两个由英文字母组成的字符串 String 和 Pattern,要求找到 Pattern 在 String 中第一次出现的位置,并将此位置后的 String 的子串输出.如果找不到,则输出“Not ...