摘要:代碼如下原生調(diào)用該文件中加入這一行代碼參數(shù)參數(shù)時(shí)間調(diào)用該文件加入這一行代碼中引入綁定到實(shí)例原型上組件中調(diào)用鄙人創(chuàng)建了一個(gè)群,供大家學(xué)習(xí)交流,希望和大家合作愉快,互相幫助,交流學(xué)習(xí),以下為群二維碼
代碼如下:
const slider = (function() { var Slider = {}; // the constructed function,timeManager,as such that"s a manager about managing the setInterval function TimerManager() { this.timers = []; this.args = []; this.isTimerRun = false; } // if the element can"t has the property of TimerManage what represented the constructor function,repeated creating a constructed function TimerManager.makeTimerManage = function(element) { if ( !element.TimerManage || element.TimerManage.constructor !== TimerManager ) { element.TimerManage = new TimerManager(); } }; // That"s order to create the method what add the timer TimerManager.prototype.add = function(timer, args) { this.timers.push(timer); this.args.push(args); this.timerRun(); }; // called the method is order to run the timer by ordering TimerManager.prototype.timerRun = function() { if (!this.isTimerRun) { var timer = this.timers.shift(), args = this.args.shift(); if (timer && args) { this.isTimerRun = true; timer(args[0], args[1]); } } }; // let it run the next timer TimerManager.prototype.next = function() { this.isTimerRun = false; this.timerRun(); }; function slideUp(element, time) { if (element.offsetHeight > 0) { var totalHeight = element.offsetHeight; var currentHeight = totalHeight; var reduceValue = totalHeight / (time / 10); element.style.transition = "height " + time + " ms"; element.style.overflow = "hidden"; var timer = setInterval(function() { currentHeight -= reduceValue; element.style.height = currentHeight + "px"; if (currentHeight <= 0) { clearInterval(timer); element.style.display = "none"; element.style.height = totalHeight + "px"; if ( element.TimerManage && element.TimerManage.constructor === TimerManager ) { element.TimerManage.next(); } } }, 10); } else { if ( element.TimerManage && element.TimerManage.constructor === TimerManager ) { element.TimerManage.next(); } } } function slideDown(element, time) { if (element.offsetHeight <= 0) { element.style.display = "block"; element.style.transition = "height" + time + " ms"; element.style.overflow = "hidden"; var totalHeight = element.offsetHeight; var currentHeight = 0; element.style.height = "0px"; var addValue = totalHeight / (time / 10); var timer = setInterval(function() { currentHeight += addValue; element.style.height = currentHeight + "px"; if (currentHeight >= totalHeight) { clearInterval(timer); element.style.height = totalHeight + "px"; if ( element.TimerManage && element.TimerManage.constructor === TimerManager ) { element.TimerManage.next(); } } }, 10); } else { if ( element.TimerManage && element.TimerManage.constructor === TimerManager ) { element.TimerManage.next(); } } } // the interface about slideUp method Slider.slideUp = function(element) { TimerManager.makeTimerManage(element); element.TimerManage.add(slideUp, arguments); return this; }; // the interface about slideDown method Slider.slideDown = function(element) { TimerManager.makeTimerManage(element); element.TimerManage.add(slideDown, arguments); return this; }; return Slider; })();
原生調(diào)用:
//該js文件中加入這一行代碼 window.slider = slider; //參數(shù)1,dom,參數(shù)2:時(shí)間 slider.slideDown(document.queryselector(),time); slider.slideUp(document.queryselector(),time);
vue.js調(diào)用:
//該js文件加入這一行代碼 export default slider; main.js中引入: import slider from "slider.js"; //綁定到Vue實(shí)例原型上 Vue.prototype.slider = slider; //組件中調(diào)用 this.slider(this.$refs,time);
鄙人創(chuàng)建了一個(gè)QQ群,供大家學(xué)習(xí)交流,希望和大家合作愉快,互相幫助,交流學(xué)習(xí),以下為群二維碼:
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/108686.html
摘要:代碼如下原生調(diào)用該文件中加入這一行代碼參數(shù)參數(shù)時(shí)間調(diào)用該文件加入這一行代碼中引入綁定到實(shí)例原型上組件中調(diào)用鄙人創(chuàng)建了一個(gè)群,供大家學(xué)習(xí)交流,希望和大家合作愉快,互相幫助,交流學(xué)習(xí),以下為群二維碼 代碼如下: const slider = (function() { var Slider = {}; // the constructed function,timeManager,...
摘要:設(shè)計(jì)的宗旨是,,即倡導(dǎo)寫更少的代碼,做更多的事情。它封裝常用的功能代碼,提供一種簡(jiǎn)便的設(shè)計(jì)模式,優(yōu)化文檔操作事件處理動(dòng)畫設(shè)計(jì)和交互。 今日任務(wù) 使用JQuery完成頁(yè)面定時(shí)彈出廣告 定時(shí)器: ? setInterval clearInterval ? setTimeout clearTimeout 顯示: img.style.display = bloc...
摘要:設(shè)計(jì)的宗旨是,,即倡導(dǎo)寫更少的代碼,做更多的事情。它封裝常用的功能代碼,提供一種簡(jiǎn)便的設(shè)計(jì)模式,優(yōu)化文檔操作事件處理動(dòng)畫設(shè)計(jì)和交互。 今日任務(wù) 使用JQuery完成頁(yè)面定時(shí)彈出廣告 定時(shí)器: ? setInterval clearInterval ? setTimeout clearTimeout 顯示: img.style.display = bloc...
摘要:設(shè)計(jì)的宗旨是,,即倡導(dǎo)寫更少的代碼,做更多的事情。它封裝常用的功能代碼,提供一種簡(jiǎn)便的設(shè)計(jì)模式,優(yōu)化文檔操作事件處理動(dòng)畫設(shè)計(jì)和交互。 今日任務(wù) 使用JQuery完成頁(yè)面定時(shí)彈出廣告 定時(shí)器: ? setInterval clearInterval ? setTimeout clearTimeout 顯示: img.style.display = bloc...
摘要:相對(duì)論極大地改變了人類對(duì)宇宙和自然的常識(shí)性觀念,提出了同時(shí)的相對(duì)性四維時(shí)空彎曲時(shí)空等全新的概念。狹義相對(duì)性原理是相對(duì)論的兩個(gè)基本假定,在目前實(shí)驗(yàn)的觀測(cè)下,物體的運(yùn)動(dòng)與相對(duì)論是吻合很好的,所以目前普遍認(rèn)為相對(duì)論是正確的理論。 7. jQuery 里的事件機(jī)制 javascript和HTML之間的交互是通過用戶和瀏覽器操作頁(yè)面時(shí)引發(fā)的事件來處理的。jQuery不僅提供了更加優(yōu)雅的事件處理...
閱讀 1963·2021-09-30 09:46
閱讀 1373·2019-08-30 15:43
閱讀 1131·2019-08-29 13:28
閱讀 1932·2019-08-29 11:24
閱讀 1693·2019-08-26 13:22
閱讀 3974·2019-08-26 12:01
閱讀 1829·2019-08-26 11:33
閱讀 3250·2019-08-23 15:34