这里主要是模拟小米官网中的首页的内容模块实现的主要动态效果

布局:采用了bootstrap框架进行布局,及其其中的字体图标

html:

<!-- 内容 -->
<div class="content_box">
<h2>内容</h2>
<div class="row content_list">
<div class="col-md-3 book_box border01">
<ul>
<li><img src="https://i1.mifile.cn/a4/61e1385e-54de-48f3-8717-5e4f4b1cdd14"></li>
<li><img src="https://s01.mifile.cn/i/index/more-duokan.jpg"></li>
<li><img src="https://i1.mifile.cn/a4/5e5da924-84e3-4959-9e25-5891cdf30757"></li>
</ul>
<span class="glyphicon glyphicon-chevron-left"></span>
<span class="glyphicon glyphicon-chevron-right"></span>
<div class="white_dian_box">
<div class="white_dian active"></div>
</div>
</div>
<div class="col-md-3 book_box border02">
<ul>
<li>
<img src="https://i1.mifile.cn/a4/xmad_15106277789889_NVKse.png">
</li>
<li>
<img src="https://i1.mifile.cn/a4/xmad_15106285428716_UgNzb.png">
</li>
<li>
<img src="https://i1.mifile.cn/a4/xmad_151062859387_ECIuV.png">
</li>
<li>
<img src="https://s01.mifile.cn/i/index/more-miui.jpg">
</li>

</ul>
<span class="glyphicon glyphicon-chevron-left"></span>
<span class="glyphicon glyphicon-chevron-right"></span>
<div class="white_dian_box">
</div>
</div>
<div class="col-md-3 book_box border03">
<ul>
<li>
<img src="https://i1.mifile.cn/a4/xmad_15094191317724_FNyjV.png">
</li>
<li>
<img src="https://i1.mifile.cn/a4/T1czW_BXCv1R4cSCrK.png">
</li>
<li>
<img src="https://i1.mifile.cn/a4/695c909b-f541-4575-bace-d08b6465025b">
</li>
<li>
<img src="https://s01.mifile.cn/i/index/more-game.jpg">
</li>

</ul>
<span class="glyphicon glyphicon-chevron-left"></span>
<span class="glyphicon glyphicon-chevron-right"></span>
<div class="white_dian_box">
</div>
</div>
<div class="col-md-3 book_box border04">
<ul>
<li>
<img src="https://i1.mifile.cn/a4/3332da7d-4056-4694-9548-c83b7b3af7d3">
</li>
<li>
<img src="https://i1.mifile.cn/a4/T1TkKvBCKv1R4cSCrK.png">
</li>
<li>
<img src="https://i1.mifile.cn/a4/T15VZvB5Kv1R4cSCrK.png">
</li>
<li>
<img src="https://s01.mifile.cn/i/index/more-app.jpg">
</li>

</ul>
<span class="glyphicon glyphicon-chevron-left"></span>
<span class="glyphicon glyphicon-chevron-right"></span>
<div class="white_dian_box">
</div>
</div>
</div>
</div>
</div>

css:

/*内容盒子属性*/
.container .content_box .content_list >div{width: 275px; overflow: hidden;}
.container .content_box .content_list .book_box{padding: 0;margin-left: 15px;height: 300px;
background: white;}
.container .content_box .content_list .border01{border-top: 1px solid orange;}
.container .content_box .content_list .border02{border-top: 1px solid green;}
.container .content_box .content_list .border03{border-top: 1px solid red;}
.container .content_box .content_list .border04{border-top: 1px solid blue;}
.container .content_box .content_list .book_box:hover{transform:translate3d(0,-2px,0);
box-shadow:0px 15px 30px rgba(0,0,0,0.1);}
.container .content_box .content_list .book_box ul li{width: 275px; float: left;}
.container .content_box .content_list .book_box .glyphicon-chevron-left,
.container .content_box .content_list .book_box .glyphicon-chevron-right{position: absolute;
top: 40%; left: 0; padding: 10px;}
.container .content_box .content_list .book_box .glyphicon-chevron-right{left: 89%;}
.container .content_box .content_list .book_box .glyphicon-chevron-left:hover,
.container .content_box .content_list .book_box .glyphicon-chevron-right:hover{
background-color: #D9D9D9;color: #fff;}
/*白点属性*/
.container .content_box .content_list .book_box .white_dian_box{position: absolute; bottom: 20px;
left:30%;}
.container .content_box .content_list .book_box .white_dian{width: 8px; height: 8px;
background: #ccc; border-radius: 50%;float: left;margin-left: 20px; }
.container .content_box .content_list .book_box .active{background: #fff; border:1px solid #FF6700;}

js:代码

// 内容里的js
var change_box={
box_length:0,
box_width:275,
cur_el:'',//当前点击的盒子
cur_el_index:'',
all_el:[],//存放不同节点的长度、盒子的位置
init:function(cur_box){
this.box_length = $('.content_box .book_box li').length
$('.content_box .book_box ul').css('width',this.box_length*this.box_width)

$(cur_box).each((index,item)=>{
let li_length = $(item).find('li').length
//this.box_length = $(item).find('li').length
this.all_el.push({
box_length:li_length,
cur_index:0
})
$(item).find('ul').css('width',li_length*this.box_width)

// 创建白点
this.create_white_dian(li_length,item)
})
// console.log(this.all_el)
$(cur_box).click((event)=>{
this.cur_el = $(event.currentTarget)//可以确定是不同的book_box
this.cur_el_index = this.cur_el.index()
if($(event.target).hasClass('glyphicon-chevron-left')){
this.change_to_left()
}else if($(event.target).hasClass('glyphicon-chevron-right')){
this.change_to_right()
}else if($(event.target).hasClass('white_dian')){
this.change_to_index($(event.target).index())
}
})
},
//显示内容和白点高亮的方法
show_content:function(show_index){
this.cur_el.find('ul').css('margin-left',-(show_index*this.box_width))
this.cur_el.find('.white_dian_box>div').removeClass('active').eq(show_index).addClass('active')
},
//点击点击白点显示对应的内容
change_to_index:function(index){
this.show_content(index)
this.all_el[this.cur_el_index].cur_index = index
},
// 创建白点方法
create_white_dian:function(dian_num,item){
let dian_html = ''
for (var i = 0; i<dian_num; i++) {
let active = ''
if(i == 0){
active = 'active'
}
dian_html += '<div class="white_dian '+active+'"></div>'
}
$(item).find('.white_dian_box').html(dian_html)
},
change_to_left:function(){
let cur_el_different_index = this.all_el[this.cur_el_index]
cur_el_different_index.cur_index--
if(cur_el_different_index.cur_index<0){
cur_el_different_index.cur_index=cur_el_different_index.box_length-1
}
// this.cur_el.find('ul').css('margin-left',-(cur_el_different_index.cur_index*this.box_width))
this.show_content(cur_el_different_index.cur_index)
},
change_to_right:function(){
let cur_el_different_index = this.all_el[this.cur_el_index]
cur_el_different_index.cur_index++
if(cur_el_different_index.cur_index>=cur_el_different_index.box_length){
cur_el_different_index.cur_index=0
}
// this.cur_el.find('ul').css('margin-left',-(cur_el_different_index.cur_index*this.box_width))
// this.cur_el.find('.white_dian_box>div').removeClass('active').eq(cur_el_different_index
// .cur_index).addClass('active')
this.show_content(cur_el_different_index.cur_index)
}
}
change_box.init('.content_list .book_box')

jQuery中面向对象思想实现盒子内容切换的更多相关文章

  1. 2017.12.25 Java中面向对象思想的深刻理解

    今日内容介绍 1.面向对象思想 2.类与对象的关系 3.局部变量和成员变量的关系 4.封装思想 5.private,this关键字 6.随机点名器 01面向对象和面向过程的思想 * A: 面向过程与面 ...

  2. jQuery中取消后续执行的内容

    <html xmlns="http://www.w3.org/1999/xhtml"><head>    <title></title&g ...

  3. JQuery中DOM事件合成用法

    jQuery有两个合成事件——hover()方法和toggle()方法 类似前面讲过的ready()方法,hover()方法和toggle()方法都属于jQuery自定义的方法. hover()方法: ...

  4. jQuery中样式和属性模块简单分析

    1.行内样式操作 目标:扩展框架实现行内样式的增删改查 1.1 创建 css 方法 目标:实现单个样式或者多个样式的操作 1.1.1 css方法 -获取样式 注意:使用 style 属性只能获取行内样 ...

  5. jQuery中的事件——《锋利的JQuery》

    虽然利用原生的JavaScript事件能完成一些交互,但jQuery增加并扩展了基本的事件处理机制.jQuery不仅提供了更加优雅的事件处理语法,而且极大地增强了事件处理能力. 1.加载DOM 在Ja ...

  6. 谈一谈原生JS中的【面向对象思想】

           [重点提前说:面向对象的思想很重要!]         最近开始接触学习后台的PHP语言,在接触到PHP中的面向对象相关思想之后,突然想到之前曾接触的JS中的面向对象思想,无奈记性太差, ...

  7. jquery中ajax中post方法(多学习:洞悉原理,触类旁通)(函数封装思想)

    jquery中ajax中post方法(多学习:洞悉原理,触类旁通)(函数封装思想) 一.总结 1.多看学习视频:洞悉原理,触类旁通, 2.函数封装:$.post(URL,data,callback); ...

  8. linux设备模型与内核中的面向对象思想

    linux内核用C语言实现了C++面向对象的大部分特性:封装,继承,多态.在看内核的过程中,开始追寻其中的设计思想,封装.继承.多态.恰好今天又在看Linux设备模型,找了很多资料.总结如下: 1.l ...

  9. 使用jQuery 中的显示与隐藏动画效果实现折叠下拉菜单的收缩和展开,在页面的列表中有若干项,列表的每项中有一个二级列表,二级列表默认为隐藏状态。点击列表的项,切换二级列表的显示或隐藏状态

    查看本章节 查看作业目录 需求说明: 使用jQuery 中的显示与隐藏动画效果实现折叠下拉菜单的收缩和展开,在页面的列表中有若干项,列表的每项中有一个二级列表,二级列表默认为隐藏状态.点击列表的项,切 ...

随机推荐

  1. Centos7.2——自定义系统服务

    前言 顾明思议,自己创建系统服务,在上一篇博文中写道了,这里就详细写下~ 步骤 我是一段美丽的用户分割的废话~ 进入到系统服务目录 ··· cd /lib/systemd/system ··· 创建服 ...

  2. JavaScript 检查 email 地址的正则表达式

    JavaScript 检查 email 地址的正则表达式​1.代码(1)<html><head><title>Checking an email address - ...

  3. WAS:修改jsp编译器用JDK5.0

      问题现象: 今天有现场反映,访问应用的个别页面报错,报错内容如下: 于是先查看其他现场,都是好的:根据报错信息,提示的意思是jsp解析不了. 结合上面2个情况,排除代码问题,应该是现场WAS环境问 ...

  4. POJ - 2115 C Looooops(扩展欧几里德求解模线性方程(线性同余方程))

    d.对于这个循环, for (variable = A; variable != B; variable += C) statement; 给出A,B,C,求在k位存储系统下的循环次数. 例如k=4时 ...

  5. codeforces 691F F. Couple Cover(组合计数)

    题目链接: F. Couple Cover time limit per test 3 seconds memory limit per test 512 megabytes input standa ...

  6. 贪吃蛇小游戏—C++、Opencv编写实现

    贪吃蛇游戏,C++.Opencv实现 设计思路: 1.显示初始画面,蛇头box初始位置为中心,食物box位置随机 2.按随机方向移动蛇头,按a.s.d.w键控制移动方向,分别为向左,向下,向右,向上 ...

  7. 【ZJOI 2008】树的统计

    [题目链接] 点击打开链接 [算法] 树链剖分模板题 [代码] #include<bits/stdc++.h> using namespace std; #define MAXN 3000 ...

  8. npm 基本命令行

    npm是随同NodeJS一起安装的包管理工具. 检查版本 npm -v 升级npm npm install npm -g 使用淘宝镜像升级 cnpm install npm -g npm instal ...

  9. UI:动画

    参考 UIView 层级管理.触摸.检测手机是否横屏.调整设备的方向 动画:为了提高用户的体验 View层的动画.UIlayer层的动画.UIView改变视图效果.UIlayer的绘图框架 #prag ...

  10. Java:String之间通过==比较的情况

    大家都知道在String之间的内容比较的时候,是通过equals函数比较的. 但是在在许多的面试题中,总是出现一堆的判断两个String对象通过==比较的结果,实际上是考的Java内存分配机制. Ja ...