html
~~~
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="css/index.css">
</head>
<body>
<div class="container">
<div class="list" id="list" style="left:-600px">
<img src="images/05.png" alt="">
<img src="images/01.png" alt="">
<img src="images/02.png" alt="">
<img src="images/03.png" alt="">
<img src="images/04.png" alt="">
<img src="images/05.png" alt="">
<img src="images/01.png" alt="">
</div>
<button id="prev"></button>
<button id="next"></button>
<div id="btns">
<span class="current"></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
</div>
<script>
var container = document.getElementById("container");
var list = document.getElementById("list");
var prev = document.getElementById("prev");
var next = document.getElementById("next");
var btns = document.getElementById("btns").children;
// 記錄焦點變化的位置
var index = 0;
var timer;
var animated = false;
// 1.點擊next,left加-600,當left<-3000時,left值等于-600
next.onclick = function () {
if(animated){
return false;
}
index++;
if (index > 4) {
index = 0;
}
showBtn();
animate(-600)
}
prev.onclick = function () {
if(animated){
return false;
}
index--;
if (index < 0) {
index = 4
}
showBtn();
animate(600)
}
// 點擊焦點換圖
for (let i = 0; i < btns.length; i++) {
btns[i].index = i;
btns[i].onclick = function () {
var offset = (this.index - index) * -600;
// index記錄焦點變化的位置
index = this.index;
animate(offset);
showBtn();
}
}
function showBtn() {
for (let i = 0; i < btns.length; i++) {
btns[i].classList.remove("current");
}
btns[index].classList.add("current");
}
function animate(offset) {
animated = true;
let time = 300;
let interval = 10;
let speed = offset / (time / interval);
let newLeft = parseInt(list.style.left) + offset;
function go() {
let leftValue = parseInt(list.style.left);
if ((speed < 0 && leftValue > newLeft) || (speed > 0 && leftValue < newLeft)) {
list.style.left = leftValue + speed + "px"
setTimeout(go, interval)
} else {
animated = false;
if (newLeft > -600) {
list.style.left = -3000 + "px"
} else if (newLeft < -3000) {
list.style.left = -600 + "px";
} else {
list.style.left = newLeft + "px";
}
}
}
go();
}
</script>
</body>
</html>
~~~
css
~~~
*{margin:0;padding:0}
.container{
margin-left: auto;
margin-right: auto;
width:600px;height:400px;
border:1px solid #333;position: relative;
overflow: hidden;
}
.list{
position: absolute;
width:4200px;
height:400px;
}
.list img{
float: left;
}
#prev,#next{
cursor: pointer;
background: url("../images//icon-slides.png");
width:40px;height:69px;position: absolute;
z-index: 100;border: none;
top:50%;transform: translateY(-50%);
}
#next{
right:0;
background-position-x:-43px;
}
#btns{
left:50%;transform: translateX(-50%);
bottom: 20px;
position: absolute;z-index:101;
}
#btns span{
cursor: pointer;
display: inline-block;
width:25px;height:25px;
background: rgba(51, 51, 51, 0.493);
border-radius: 50%;
}
#btns .current{
background:#ff8936
}
~~~
- JavaScript介紹
- js基本語法
- 調試方法
- 標識符
- 數據類型(基本,引用)
- 基本數據類型
- 引用數據類型
- 嚴格模式.
- 全局變量和局部變量
- DOM 節點
- DOM 改變元素內容(樣式 內容)
- 節點改變元素內容(通過父子節點找到元素然后操作)
- 添加元素
- 設置 移除 屬性
- DOM下的事件
- 知識點整理
- 異步
- Ajax
- this指向問題
- 設備類型檢測(手機 平板 電腦)
- 函數
- 函數的參數
- 重載
- 數據類型
- 構造函數
- 返回上一個網頁
- 數組 (重點)
- 增加數組內容
- 刪除數組元素
- 復制數組
- 修改數組元素(功能強大實現 增 刪 改)
- 數組元素查詢
- 數組遍歷
- 最值
- 展開語法
- join
- 排序問題
- 求和
- 顛倒數組
- 判斷是不是一個數組
- 二維數組
- 數組和字符串之間轉換
- 數組去重
- 將jquery對象轉為javascript對象
- 元素偏移量
- 獲取一個元素距離頂部的距離
- 可視區域寬高
- 布局視口 (移動設備)
- 文檔碎片
- 表格中的 thead tbody
- 獲取元素寬度
- 滾動區域寬高
- div滾動條設置
- 使用 offsetWidth 設置父元素寬度和子元素寬度之和一樣
- 字符串的方法
- js功能實現
- 點擊顯示 隱藏
- 點擊變色 兄弟元素隱藏.
- 點擊顯示隱藏區域.
- 兼容性問題.
- 選擇按鈕,
- 獲取外部樣式
- 點擊彈出下標
- 通過屬性改變img 的src
- 小米登錄 es6實現js
- try catch
- 小米登錄es5實現js
- js實現導航欄點擊加載多個頁面
- js實現網頁之間的跳轉和在指定div加載頁面
- iframe 高度實現自適應
- js 獲取滾動條距離頂端的距離
- jQuery animate() 方法 動畫效果
- fade(js實現遮罩層漸變色)
- js輪播實現
- 超哥輪播js
- 輪播動畫原理
- 數組實現瀑布流
- 電子表計時器date
- 從豆瓣接口上取數據實現搜索功能(重點!!!!)
- 封裝
- 不使用js-ajax 使用VueResource實現數據請求
- 需要常看的知識點
- 移動端響應布局rem
- rem+vw
- 原型
- JS的模塊化如何解決
- ES5和ES6模塊化寫法
- js內置對象
- 結構賦值es6
- 字符串模板 分割字符串
- 談基本數據類型中的方法(本不帶有方法)
- Math
- date
- 正則
- 備選字符集
- 連號的備選字符集
- replace() 查找替換(過濾)
- 量詞
- 不確定的數量
- search找下標
- test()檢驗是否包含正則表達式
- 實例
- 驗證電話號碼
- 郵箱驗證
- 將指定內容過濾(天貓 淘寶)
- 預定義字符集(簡化)
- 嚴格匹配 ^ $
- Ajax
- http get post
- $.get()和$.post()詳解
- jquery-ajax 數據請求
- 使用Vue Ajax在網頁中渲染數據
- axios向服務器端get,post數據(重點)
- 跨域
- 原生Ajax
- 原理步驟 json解析字符串
- 多態
- js中的面向對象
- js中的類和繼承
- 原型和原型鏈
- 參數表達式
- 字符串中常用的方法
- mock.js
- scrollReveal 滾動顯示
- Node.js模塊里exports與module.exports的區別