## html的布局
```
<!--輪播層-->
<div class="slide_once">
<ul id="slideBanner">
<li>
<img src="./img/slide1.jpg" alt="">
</li>
<li>
<img src="./img/slide2.jpg" alt="">
</li>
<li>
<img src="./img/slide3.jpg" alt="">
</li>
</ul>
<div class="controller clearfix" id="topSlide">
<!--<span class="current"></span>-->
<!--<span></span>-->
<!--<span></span>-->
</div>
</div>
```
## 樣式
```
.slide_once .controller {
position: absolute;
height:40px ;
left: 50%;
transform: translateX(-50%);
bottom:90px;
}
.slide_once .controller span {
box-sizing: border-box;
margin-top: 10px;
display: block;
width: 20px;
height: 20px;
border-radius: 50%;
background: #fff9e5;
margin-left: 20px;
margin-right: 20px;
float: left;
}
.slide_once .controller .current {
width: 36px;
height: 36px;
background: url("../img/video.png");
margin-top: 0;
}
.more .slide_con ul {
width: 600%;
position: absolute;
left: 0;
top: 0;
}
.more .slide_con li {
float: left;
height: 100%;
width: 1200px;
}
.slide .slide_once {
width: 100%;
height: 100%;
overflow: hidden;
}
.slide_once li img {
width: 100%;
height: 960px;
}
```
## js
```
/* *
* desc: 輪播圖
* time: 2018-12-1
* author: Marvin
* @param{Object} 配置參數 參數說明
* @param{ulId}: ul的id
* @param{controlId}: 控制器span盒子的id
* @param{epeed}: 輪播圖的速度
* @param{width}: 輪播圖片的寬度
* @param{height} : 輪播圖的高度
* @param{currentClassname} : 當前輪播的class
* @param{currentspecial} : 當前特殊輪播的class
*/
function Slide(option) {
this.parent = document.querySelector(option.ulId) || null;
this.control = document.querySelector(option.controlId) || null;
this.index = 0;
this.square = 0;
this._init(option);
}
Slide.prototype = {
_init: function (option) {
/*所有的輪播的盒子*/
this.listArray = this.parent.children;
/*所有輪播盒子的個數*/
this.listLength = this.listArray.length;
/*復制第一張的圖片到ul 的最后*/
this.parent.appendChild(this.parent.children[0].cloneNode(true));
/*輪播圖片的寬度以及高度*/
this.liHeight = option.height;
this.liWidth = option.width;
this.speed = option.speed;
this.currentClassname = option.currentClassname;
this.currentspecial = option.currentspecial || option.currentClassname;
},
reset:function () {
var that = this;
this.index = 0;
this.square = 0;
clearInterval(that.timer)
},
beforePlay: function () {
var that = this;
var str = ''
/*初始化樣式*/
this.setStyle(that.parent, {'width': Number(that.listLength+1) * parseInt(that.liWidth) + 'px'});
for (var i = 0; i < that.listArray.length; i++) {
that.setStyle(that.listArray[i], {'width': that.liWidth, 'height': that.liHeight});
}
for (var i = 0; i < that.listArray.length-1; i++) {
str += '<span></span>'
}
/*綁定span的內容*/
that.control.innerHTML = str;
/*初始化span的樣式*/
that.addClassMany(that.control.children[0],[that.currentClassname]);
},
play: function () {
var that = this;
var len = this.control.children
for(var i = 0; i < len.length; i ++) {
len[i].index = i; // 獲得當前第幾個小li 的索引號
len[i].onclick = function() {
// console.log(this.index)
// console.log(that.square)
for(var j=0;j<len.length;j++)
{
len[j].className = ""; // 所有的都要清空
}
this.className = that.currentClassname;
that.animateM(that.parent,-this.index* parseInt(that.liWidth))
that.index = that.square = this.index
}
}
that.index ++;
if(that.index > (that.listLength)) {
that.parent.style.left = 0
that.index = 1;
}
that.animateM(that.parent,-that.index* parseInt(that.liWidth));
that.square++;
if(that.square > that.listLength -1)
{
that.square = 0;
}
for(var i=0;i<that.control.children.length;i++) // 先清除所有的
{
that.control.children[i].className = ""
}
/*給當前的控制器span添加class*/
that.addClassMany(that.control.children[that.square], [that.currentClassname])
},
autoPlay:function () {
var that = this;
clearInterval(timer)
var timer = null;
that.beforePlay();
timer = setInterval(function () {
that.play()
},that.speed)
},
animateM: function (obj, target) {
clearInterval(obj.timer);
obj.timer = setInterval(function () {
var step = (target - obj.offsetLeft) / 10;
step = step > 0 ? Math.ceil(step) : Math.floor(step);
obj.style.left = obj.offsetLeft + step + "px";
if (obj.offsetLeft == target) {
clearInterval(obj.timer);
}
}, 10)
},
/*獲取屬性函數*/
getStyle: function (obj, attr) { // 誰的 那個屬性
obj.currentStyle = '';
if (obj.currentStyle) // ie 等
{
return obj.currentStyle[attr]; // 返回傳遞過來的某個屬性
}
else {
return window.getComputedStyle(obj, null)[attr]; // w3c 瀏覽器
}
},
/*設置屬性*/
/*des:josn的key和value必須是字符串*/
setStyle: function (dom, josn) {
for (var key in josn) {
var styleK = key;
var styleV = josn[key];
if (dom.length) {
for (var i = 0, len = dom.length; i < len; i++) {
dom[i].style[styleK] = styleV;
}
return;
}
dom.style[styleK] = styleV;
}
return
},
/*
*添加多個類名
*element: 元素
*classnameArr:類名的數組
*/
addClassMany: function (element, classnameArr) {
var classNameArr = (element.className).split(' ') || [];
var newClassNameStr = '';
if (arguments.length != 2 && !(classnameArr instanceof Array)) {
throw new Error("參數形式個數不正確");
}
if (classNameArr == null) {
var newClassName = classnameArr;
} else {
for (var i in classnameArr) {
classNameArr.push(classnameArr[i]);
}
newClassNameStr = classNameArr.join(' ');
}
element.className = newClassNameStr;
return;
}
}
```
- css用法技巧
- 陰影被后面div遮擋
- 繪制一個三角形
- 圖像的灰白處理
- 一切居中
- 禁用鼠標事件
- 模糊文本
- 字體省略號
- 垂直居中
- box投影
- css動畫
- javaScript常見工具封裝
- 地址欄參數獲取
- 日期格式化
- Ajax
- scroll
- 緩動函數
- 事件綁定
- 阻止冒泡和默認行為
- 偽數組正常化
- 日期生成
- 拷貝
- javaScript基本知識
- javaScript基本知識
- javascript常見代碼塊
- vue常見問題
- 獲取參數
- vue常見問題/vue混入
- v-html指令問題集錦
- 正則獲取html中所有的中文字符
- 時間格式化
- 監聽路由的變化
- vue移動端滑動事件
- vue移動端圖片點擊放大
- 打包后背景圖片404的問題
- webpack打包后部分樣式失效
- IE的兼容問題
- post請求后臺無法接受參數
- 驗證碼
- vue開啟Gzip報錯
- v-html修改樣式
- app.css文件過大
- vue中中使用iframe
- babel對es6編譯不徹底 出現ie不兼容的問題
- vue單頁應用優化
- 吸頂問題
- 跨域session無法共享
- 登陸返回上一頁
- axois中使用delete數據傳遞問題
- 監聽數組對象數組中的屬性
- webpack
- webpack基本使用
- webpack打包刪除注釋
- js插件
- 輪播圖
- 面向對象模板
- 左滑右滑
- 存儲
- appcan
- appcan
- js深入研究
- 數組的參數傳遞問題
- 采用jquery的方法載入公共頁面后出現閃爍的問題
- html拼接無法綁定事件
- 吸頂問題
- async配合promise使用
- flutter
- 模擬器加載報錯
- 底部導航實現
- 模擬器出現錯誤
- flutter在idea下的快捷鍵
- flutter學習筆記
- 設計模式
- 觀察者模式
- nest
- nest基本說明
- nest錯誤處理
- vue高級
- 動態注入路由
- nest實戰
- 一項目準備
- window
- 端口進程被占
- mis包
- reactNative
- react-native-router-flux
- esLint
- eslint
- Cesium