jQuery箭头切换图片 - 学习笔记
jQuery箭头切换图片
- 布局
- 3d位移 变形原点
- jQuery
transform:translate3d(x,y,z);
x 代表横向坐标移向量的长度
y 代表纵向坐标移向量的长度
z 代表Z轴移向量的长度 取值不可为百
scale() 缩放
transform-origin:0 50%;
top left | left top 等价于 0 0
top | top center | center top 等价于 50% 0
right top | top right 等价于 100% 0
left | left center | center left 等价于 0 50%
center | center center 等价于 50% 50%(默认值)
right | right center | center right 等价于 100% 50%
bottom left | left bottom 等价于 0 100%
bottom | bottom center | center bottom 等价于 50% 100%
bottom right | right bottom 等价于 100% 100%
left,center right是水平方向取值,对应的百分值为left=0%;center=50%;right=100%
top center bottom是垂直方向的取值,其中top=0%;center=50%;bottom=100%;
HTML 部分
- <!DOCTYPE HTML>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <title>jQuery箭头按钮切换图片</title>
- <script type="text/javascript" src="js/jquery-3.1.1.min.js"></script>
- </head>
- <body>
- <div class="box">
- <div class="list">
- <ul>
- <li class="p7"><a href="#"><img src="img/1.png" alt="" /></a></li>
- <li class="p6"><a href="#"><img src="img/2.png" alt="" /></a></li>
- <li class="p5"><a href="#"><img src="img/3.png" alt="" /></a></li>
- <li class="p4"><a href="#"><img src="img/44.jpg" alt="" /></a></li>
- <li class="p3"><a href="#"><img src="img/55.jpg" alt="" /></a></li>
- <li class="p2"><a href="#"><img src="img/66.jpg" alt="" /></a></li>
- <li class="p1"><a href="#"><img src="img/77.jpg" alt="" /></a></li>
- </ul>
- </div>
- <a href="javascript:;" class="prev btn"><</a>
- <a href="javascript:;" class="next btn">></a>
- </div>
- </body>
- </html>
CSS 部分
- <style type="text/css">
- *{
- margin: 0;
- padding: 0;
- }
- .box{
- margin-top: 80px;
- width: 100%;
- height: 340px;
- position: relative; /* 相对定位 */
- }
- .list{
- width: 1200px;
- height: 300px;
- overflow: hidden;
- position: absolute;
- left: 50%;
- margin-left: -600px;
- }
- .btn{
- position: absolute; /* 绝对定位 */
- top: 50%;
- margin-top: -50px;
- width: 60px;
- height: 100px;
- line-height: 100px; /* 行高 */
- font-size: 30px;
- color: white;
- text-decoration: none; /* 文本修饰 */
- text-align: center;
- background: rgba(0,255,0,.5);
- cursor: pointer; /* 光标的样式 改为手指 */
- }
- .next{
- right: 0;
- }
- li{
- position: absolute;
- top: 0;
- left: 0;
- list-style: none;
- opacity: 0;
- transition: all 0.3s ease-out;
- }
- img{
- width: 751px;
- height: 300px;
- border:none;
- float: left;
- }
- .p1{
- transform:translate3d(-224px,0,0) scale(0.81);
- /* 3d位移 x,y,z
- x 代表横向坐标移向量的长度
- y 代表纵向坐标移向量的长度
- z 代表Z轴移向量的长度 取值不可为百分比
- */
- }
- .p2{
- transform:translate3d(0px,0,0) scale(0.81);
- transform-origin:0 50%; /* 变形原点 */
- /* top left | left top 等价于 0 0
- top | top center | center top 等价于 50% 0
- right top | top right 等价于 100% 0
- left | left center | center left 等价于 0 50%
- center | center center 等价于 50% 50%(默认值)
- right | right center | center right 等价于 100% 50%
- bottom left | left bottom 等价于 0 100%
- bottom | bottom center | center bottom 等价于 50% 100%
- bottom right | right bottom 等价于 100% 100%
- */
- /*
- left,center right是水平方向取值,对应的百分值为left=0%;center=50%;right=100%
- top center bottom是垂直方向的取值,其中top=0%;center=50%;bottom=100%; 如果只取一个值,表示垂直方向值不变。
- */
- opacity: 0.8;
- z-index: 2;
- }
- .p3{
- transform:translate3d(224px,0,0) scale(1);
- z-index: 3;
- opacity: 1;
- }
- .p4{
- transform:translate3d(449px,0,0) scale(0.81);
- transform-origin:100% 50%;
- opacity: 0.8;
- z-index: 2;
- }
- .p5{
- transform:translate3d(672px,0,0) scale(0.81);
- }
- .p6{
- transform:translate3d(896px,0,0) scale(0.81);
- }
- .p7{
- transform:translate3d(1120px,0,0) scale(0.81);
- }
- </style>
JavaScript 部分
- <script type="text/jscript">
- var cArr=["p7","p6","p5","p4","p3","p2","p1"];
- var index=0;
- $(".next").click( //下一张
- function(){
- nextimg();
- }
- )
- $(".prev").click( //上一张
- function(){
- previmg();
- }
- )
- //上一张
- function previmg(){
- cArr.unshift(cArr[6]); //向数组的开头添加一个或更多元素 并返回新的长度
- cArr.pop(); //移除最后一个元素
- //i是元素的索引,从0开始
- //e为当前处理的元素
- //each循环,当前处理的元素移除所有的class,然后添加数组索引i的class
- $("li").each(function(i,e){
- $(e).removeClass().addClass(cArr[i]);
- })
- index--;
- if (index<0) {
- index=6;
- }
- show();
- }
- //下一张
- function nextimg(){
- cArr.push(cArr[0]); //向数组的末尾添加一个或更多元素 并返回新的长度
- cArr.shift(); //删除元素数组中的第一个值 并返回
- $("li").each(function(i,e){
- $(e).removeClass().addClass(cArr[i]);
- })
- index++;
- if (index>6) {
- index=0;
- }
- show();
- }
- </script>
此文到此结束
此文参考 http://www.w3cplus.com/css3/css3-3d-transform.html
jQuery箭头切换图片 - 学习笔记的更多相关文章
- 《jQuery权威指南》学习笔记之第2章 jQuery选择器
2.1 jQuery选择器概述 2.1.1 什么使选择器 2.1.2 选择器的优势: 代码更简单,完善的检测机制 1.代码更简单 示例2-1 使用javascript实现隔行变色 < ...
- 锋利的jQuery第2版学习笔记4、5章
第4章,jQuery中的事件和动画 注意:使用的jQuery版本为1.7.1 jQuery中的事件 JavaScript中通常使用window.onload方法,jQuery中使用$(document ...
- 锋利的jQuery第2版学习笔记8~11章
第8章,用jQuery打造个性网站 网站结构 文件结构 images文件夹用于存放将要用到的图片 styles文件夹用于存放CSS样式表,个人更倾向于使用CSS文件夹 scripts文件夹用于存放jQ ...
- 锋利的jQuery第2版学习笔记1~3章
第1章,认识jQuery 注意:使用的jQuery版本为1.7.1 目前流行的JavaScript库 Prototype(http://www.prototypejs.org),成型早,面向对象的思想 ...
- 锋利的jQuery第2版学习笔记6、7章
第6章,jQuery与Ajax的应用 Ajax的优势和不足 Ajax的优势 1.不需要插件支持 2.优秀的用户体验 3.提高Web程序的性能 4.减轻服务器和带宽的负担 Ajax的不足 1.浏览器对X ...
- jQuery 自定义事件的学习笔记
jquery中提供了两种方法可以绑定自定义事件: bind()和one()而绑定的自定义事件的触发,必须得用jquery中的trigger()方法才能触发. 我们先来看on事件 代码如下 复制代码 ...
- jquery无new构建学习笔记
当我们想要创建一个对象,我们可能使用new方法去构建一个对象,那按道理jquery也是一个对象,应该也是用new jquery()来构建呀为什么我们创建jquery对象不用new jquery()而是 ...
- jquery类数组结构学习笔记
大家都知道我们使用$()产生的jquery对象可以使用下标去获取对应下标的元素. 举个栗子,一个页面有5个div标签,我们使用$("div")去获取到这些元素,然后我们就可以使用$ ...
- ps切图 切png图片——学习笔记
第一步:新建一个图层,点击ps左上角“文件”,然后新建即可(或crtl+alt+n) 参数自己随便填,注意背景图片选择透明即可. 第二步:打开psd文件,点击工具中的“移动工具”,之后选中上面的“自动 ...
随机推荐
- nodejs改变代码不需要重启的方法
1.node 搭建本地服务器 在F:/node文件夹下新建app.js const http = require('http'); http.createServer((req, res) => ...
- nginx并发连接控制模块ngx_http_limit_conn_module
模块: ngx_http_limit_conn_module 作用: 根据定义的key限制并发连接数 配置示例: http { limit_conn_zone $binary_remote_addr ...
- Windows下安装MySQL详细教程
Windows下安装MySQL详细教程 1.安装包下载 2.安装教程 (1)配置环境变量 (2)生成data文件 (3)安装MySQL (4)启动服务 (5)登录MySQL (6)查询用户密码 (7 ...
- CentOS7搭建FastDFS V5.11分布式文件系统-第二篇
1.CentOS7 FastDFS搭建 前面已下载好了要用到的工具集,下面就可以开始安装了: 如果安装过程中出现问题,可以下载我提供的,当前测试可以通过的工具包: 点这里点这里 1.1 安装libfa ...
- Linux终端复用工具 tmux
简介 Terminal Multiplexer (From WIKIPEDIA) - A terminal multiplexer is a software application that can ...
- JVM调优一些相关内容
JVM调优工具 Jconsole,jProfile,VisualVM Jconsole : jdk自带,功能简单,但是可以在系统有一定负荷的情况下使用.对垃圾回收算法有很详细的跟踪.详细说明参考这里 ...
- centos6.7 安装 virtualBox 再安装 centos 7
Tag: 黄色为自己实际情况需要设置的部分,绿色部分为虚拟机名称(自定义) 1.创建虚拟机VBoxManage createvm --name centos7 --ostype Linux26_64 ...
- java学习-GET方式抓取网页(UrlConnection和HttpClient)
抓取网页其实就是模拟客户端(PC端,手机端...)发送请求,获得响应数据documentation,解析对应数据的过程.---自己理解,错误请告知 一般常用请求方式有GET,POST,HEAD三种 G ...
- Cacheable redis 宕机
使用Cacheable注解Redis方法时,如果Redis服务器挂了,就直接抛出异常了, java.net.ConnectException: Connection refused: connect ...
- .Net Core使用 MiniProfiler 进行性能分析(转)
转自:http://www.cnblogs.com/ideacore/p/9505425.html 官方文档: https://miniprofiler.com/dotnet/AspDotNetCor ...