最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

js實(shí)現(xiàn)上下滑動輪播

 更新時間:2022年07月13日 14:29:31   作者:南初?  
這篇文章主要為大家詳細(xì)介紹了js實(shí)現(xiàn)上下滑動輪播,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了js實(shí)現(xiàn)上下滑動輪播的具體代碼,供大家參考,具體內(nèi)容如下

一、效果圖

二、設(shè)計思路

第一步:遍歷所有的元素使得鼠標(biāo)點(diǎn)擊右側(cè)小圖時,圖片變亮并且根據(jù)偏移值加上紅框。點(diǎn)擊右邊的小圖左邊出現(xiàn)對用的圖片。

第二步:利用循環(huán)計時器,克隆ul里面的第一個元素使得連續(xù)循環(huán)滑動。

第三步:鼠標(biāo)進(jìn)入時循環(huán)滑動停止,離開時繼續(xù)。

第四步:設(shè)置上下按鈕,當(dāng)?shù)谝粡垐D片的offsetTop值為0時,下面按鈕出現(xiàn),當(dāng)?shù)竭_(dá)底部最后一個元素時,上面按鈕出現(xiàn),底部按鈕消失,當(dāng)在整個元素中間時,上下按鈕都出現(xiàn),每點(diǎn)擊一次按鈕移動一個格子,左邊圖片也對應(yīng)改變。

三、核心代碼

//找到right-btn 元素添加事件
var righttBtnList;
var Line;
var transy = 0;
var liHeight = 430;
var ulItem;
var count = 0;
var timer;
var speed = 2000;
var Item;
var ItemMenu;
var offsetTop = 0;
var itemtabinfo, topBtn, bottomBtn;
? ? window.onload = function () {
? ? ? ? righttBtnList = document.getElementsByClassName("right-btn");
? ? ? ? Line = document.getElementsByClassName("line")[0];
? ? ? ? ulItem = document.getElementsByClassName("item-child-ul")[0];
? ? ? ? Item = document.getElementsByClassName("item-list")[0];
? ? ? ? ItemMenu = document.getElementsByClassName("item-menu")[0];
? ? ? ? itemtabinfo = document.getElementsByClassName("item-tab-info")[0];
? ? ? ? topBtn = document.getElementsByClassName("top-btn")[0];
? ? ? ? bottomBtn = document.getElementsByClassName("bottom-btn")[0];
? ? ? ? //默認(rèn)復(fù)制第一張?zhí)砑拥絬lItem之中
? ? ? ? ulItem.appendChild(ulItem.children[0].cloneNode(true));
? ? ? ? //設(shè)置itemtabinfo 默認(rèn)移動值
? ? ? ? itemtabinfo.style.transform = "translateY(" + offsetTop + "px)";
? ? ? ? //直接默認(rèn)啟動計時器
? ? ? ? Animate();
? ? ? ? //遍歷所有的li添加事件
? ? ? ? for (var i = 0; i < righttBtnList.length; i++) {
? ? ? ? ? ? righttBtnList[i].index = i;
? ? ? ? ? ? righttBtnList[i].onclick = function () {
? ? ? ? ? ? ? ? //點(diǎn)擊當(dāng)前移除top-white
? ? ? ? ? ? ? ? if (checkClass(this, 'top-white')) {
? ? ? ? ? ? ? ? ? ? this.classList.remove("top-white");
? ? ? ? ? ? ? ? ? ? //其余的添加
? ? ? ? ? ? ? ? ? ? addWhite(this.index);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? //獲取偏移值
? ? ? ? ? ? ? ? Line.style.top = ((this.index * 110 + 10) + offsetTop) + "px";
? ? ? ? ? ? ? ? //輸出當(dāng)前點(diǎn)擊的索引
? ? ? ? ? ? ? ? ulItem.style.transform = "translateY(" + (-this.index * liHeight) + "px)";
? ? ? ? ? ? ? ? //用戶點(diǎn)擊的索引 ?對應(yīng)count值
? ? ? ? ? ? ? ? count = this.index;
? ? ? ? ? ? }
? ? ? ? }

? ? ? ? Item.onmouseenter=function(){
? ? ? ? ? ? clearTimeout(timer);
? ? ? ? }
? ? ? ? Item.onmouseleave=function(){
? ? ? ? ? ? Animate();
? ? ? ? }
? ? ? ? topBtn.onclick = function () {
? ? ? ? ? ? offsetTop += 110;
? ? ? ? ? ? //獲取原來的top
? ? ? ? ? ? var oldTop = parseFloat(Line.style.top);
? ? ? ? ? ? Line.style.top = (oldTop + 110) + "px";
? ? ? ? ? ? itemtabinfo.style.transform = "translateY(" + offsetTop + "px)";
? ? ? ? ? ? checkBtnShow();
? ? ? ? }
? ? ? ? bottomBtn.onclick = function () {
? ? ? ? ? ? offsetTop -= 110;
? ? ? ? ? ? //獲取原來的top
? ? ? ? ? ? var oldTop = parseFloat(Line.style.top);
? ? ? ? ? ? //只能取到行內(nèi)樣式
? ? ? ? ? ? Line.style.top = (oldTop - 110) + "px";
? ? ? ? ? ? itemtabinfo.style.transform = "translateY(" + offsetTop + "px)";
? ? ? ? ? ? checkBtnShow();
? ? ? ? }

? ? ? ? ItemMenu.onmouseenter = function () {
? ? ? ? ? ? checkBtnShow();
? ? ? ? }
? ? ? ? function checkBtnShow() {
? ? ? ? ? ? if (offsetTop == 0) {
? ? ? ? ? ? ? ? //下面按鈕出現(xiàn)
? ? ? ? ? ? ? ? bottomBtn.classList.add("showBottom");
? ? ? ? ? ? ? ? topBtn.classList.remove("showTop");

? ? ? ? ? ? }
? ? ? ? ? ? else if (offsetTop == -220) {
? ? ? ? ? ? ? ? //上面按鈕出現(xiàn)
? ? ? ? ? ? ? ? topBtn.classList.add("showTop");
? ? ? ? ? ? ? ? bottomBtn.classList.remove("showBottom");
? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? //兩個按鈕同時出現(xiàn)
? ? ? ? ? ? ? ? bottomBtn.classList.add("showBottom");
? ? ? ? ? ? ? ? topBtn.classList.add("showTop");
? ? ? ? ? ? }
? ? ? ? }

? ? ? ? ItemMenu.onmouseleave = function () {
? ? ? ? ? ? bottomBtn.classList.remove("showBottom");
? ? ? ? ? ? topBtn.classList.remove("showTop");
? ? ? ? }
? ? ? ? //檢測是否具有top-white
? ? ? ? function checkClass(obj,className){
? ? ? ? ? ? return obj.classList.contains(className);
? ? ? ? }
? ? ? ? //其余的li添加
? ? ? ? function addWhite(index){
? ? ? ? ? ? for(var i=0;i<righttBtnList.length;i++){
? ? ? ? ? ? ? ? if(i!=index){
? ? ? ? ? ? ? ? ? ? righttBtnList[i].classList.add("top-white");
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? //啟動計時器動畫
? ? ? ? function Animate(){
? ? ? ? ? ? //寫執(zhí)行代碼
? ? ? ? ? ? timer=setInterval(function(){
? ? ? ? ? ? ? ? if (timer)
? ? ? ? ? ? ? ? ? ? clearInterval(timer);
? ? ? ? ? ? ? ? if(!ulItem.classList.contains("transY")){
? ? ? ? ? ? ? ? ? ? ulItem.classList.add("transY");
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? count++;
? ? ? ? ? ? ? ? ulItem.style.transform="translateY("+(-count*liHeight)+"px)";
? ? ? ? ? ? ? ? //找出當(dāng)前每一張圖動畫完成時間
? ? ? ? ? ? ? ? setTimeout(function(){
? ? ? ? ? ? ? ? ? ? if(count>=ulItem.children.length-1){
? ? ? ? ? ? ? ? ? ? ? ? count=0;
? ? ? ? ? ? ? ? ? ? ? ? //移除過渡類
? ? ? ? ? ? ? ? ? ? ? ? ulItem.classList.remove("transY");
? ? ? ? ? ? ? ? ? ? ? ? ulItem.style.transform="translateY(0px)";
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? //讓右邊的元素動畫對應(yīng)
? ? ? ? ? ? ? ? ? ? //rigthBtnlist[count].click();
? ? ? ? ? ? ? ? },500)
? ? ? ? ? ? },speed)
? ? ? ? }
? ? }?

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • layui時間控件選擇時間范圍的實(shí)現(xiàn)方法

    layui時間控件選擇時間范圍的實(shí)現(xiàn)方法

    今天小編就為大家分享一篇layui時間控件選擇時間范圍的實(shí)現(xiàn)方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-09-09
  • 微信小程序自定義彈框效果

    微信小程序自定義彈框效果

    這篇文章主要為大家詳細(xì)介紹了微信小程序自定義彈框效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-07-07
  • JS代碼判斷IE6,IE7,IE8,IE9的函數(shù)代碼

    JS代碼判斷IE6,IE7,IE8,IE9的函數(shù)代碼

    JS代碼判斷瀏覽器版本,支持IE6,IE7,IE8,IE9!做網(wǎng)頁有時候會用到JS檢測IE的版本,下面是檢測Microsoft Internet Explorer版本的三種代碼
    2013-08-08
  • JavaScript判斷對象和數(shù)組的兩種方法

    JavaScript判斷對象和數(shù)組的兩種方法

    這篇文章主要介紹了JavaScript判斷對象和數(shù)組的兩種方法,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-05-05
  • 自定義滾動條3.0

    自定義滾動條3.0

    圖片自定義滾動條3.0(Duma“自動渲染版”,也許世間萬物都會變,但是真摯的愛,卻永遠(yuǎn)留存在心中?。?/div> 2009-07-07
  • 原生JS實(shí)現(xiàn)平滑回到頂部組件

    原生JS實(shí)現(xiàn)平滑回到頂部組件

    返回頂部組件是一種極其常見的網(wǎng)頁功能,需求簡單:頁面滾動一定距離后,顯示返回頂部的按鈕,點(diǎn)擊該按鈕可以將滾動條滾回至頁面開始的位置,接下來通過本文給大家介紹原生JS實(shí)現(xiàn)平滑回到頂部組件,需要的朋友參考下吧
    2016-03-03
  • js split函數(shù)用法總結(jié)(從入門到精通)

    js split函數(shù)用法總結(jié)(從入門到精通)

    js split就是將一字符串以特定的字符分割成數(shù)組,數(shù)組一般是字符串處理比較常用的處理方法
    2013-03-03
  • 5個讓你眼前一亮的JavaScript裝飾器技巧

    5個讓你眼前一亮的JavaScript裝飾器技巧

    JavaScript?裝飾器是一種特殊的功能,允許在不修改源代碼的情況下動態(tài)修改類和函數(shù)的行為,本文將介紹五個讓你眼前一亮的裝飾器技巧,包括裝飾函數(shù)參數(shù)、裝飾類屬性、裝飾函數(shù)返回值和裝飾函數(shù)調(diào)用,需要的朋友可以參考下
    2023-06-06
  • JavaScript 繼承詳解(六)

    JavaScript 繼承詳解(六)

    在本章中,我們將分析Prototypejs中關(guān)于JavaScript繼承的實(shí)現(xiàn),需要的朋友可以參考下
    2016-10-10
  • 一篇文章掌握RequireJS常用知識

    一篇文章掌握RequireJS常用知識

    一篇文章掌握RequireJS常用知識,通過本文,你可以對模塊化開發(fā)和AMD規(guī)范有一個較直觀的認(rèn)識,并詳細(xì)地學(xué)習(xí)RequireJS這個模塊化開發(fā)工具的常見用法,感興趣的小伙伴們可以參考一下
    2016-01-01

最新評論

青田县| 临潭县| 旬阳县| 新闻| 沈丘县| 瑞金市| 沈丘县| 东港市| 都江堰市| 平湖市| 罗城| 静宁县| 威信县| 孙吴县| 蓬溪县| 铜川市| 禹城市| 孟村| 夏邑县| 荥经县| 汉沽区| 汾西县| 濮阳县| 芜湖县| 绥中县| 酉阳| 双柏县| 湟源县| 永兴县| 汪清县| 高阳县| 岢岚县| 武冈市| 烟台市| 奈曼旗| 都江堰市| 鄢陵县| 伊通| 巩义市| 汉沽区| 惠安县|