国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

JS實現(xiàn)圖片旋轉(zhuǎn)動畫效果封裝與使用示例

2019-11-19 13:31:53
字體:
供稿:網(wǎng)友

本文實例講述了JS實現(xiàn)圖片旋轉(zhuǎn)動畫效果封裝與使用。分享給大家供大家參考,具體如下:

核心封裝代碼如下:

//圖片動畫封裝function SearchAnim(opts) {    for(var i in SearchAnim.DEFAULTS) {      if (opts[i] === undefined) {        opts[i] = SearchAnim.DEFAULTS[i];      }    }    this.opts = opts;    this.timer = null;    this.elem = document.getElementById(opts.elemId);    this.startAnim();}SearchAnim.prototype.startAnim = function () {    this.stopAnim();    this.timer = setInterval(() => {      var startIndex = this.opts.startIndex;      if (startIndex == 360) {        this.opts.startIndex = 0;      }      this.elem.style.transform = "rotate("+ (startIndex) +"deg)";      this.opts.startIndex += 5;    }, this.opts.delay);    setTimeout(() => {      this.stopAnim();    }, this.opts.duration);}SearchAnim.prototype.stopAnim = function() {    if (this.timer != null) {      clearInterval(this.timer);    }}SearchAnim.DEFAULTS = {    duration : 60000,    delay : 200,    direction : true,    startIndex : 0,    endIndex : 360}

使用方法:

隨便創(chuàng)建一img標(biāo)簽

然后如下調(diào)用即可:

new SearchAnim({  elemId : "wait-icon",  delay : 20,});

完整示例代碼:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>www.survivalescaperooms.com JS旋轉(zhuǎn)動畫</title></head><img src="https://files.VeVB.COm/file_images/article/201807/201879100307926.jpg" id="wait-icon"/><script>//圖片動畫封裝function SearchAnim(opts) {    for(var i in SearchAnim.DEFAULTS) {      if (opts[i] === undefined) {        opts[i] = SearchAnim.DEFAULTS[i];      }    }    this.opts = opts;    this.timer = null;    this.elem = document.getElementById(opts.elemId);    this.startAnim();}SearchAnim.prototype.startAnim = function () {    this.stopAnim();    this.timer = setInterval(() => {      var startIndex = this.opts.startIndex;      if (startIndex == 360) {        this.opts.startIndex = 0;      }      this.elem.style.transform = "rotate("+ (startIndex) +"deg)";      this.opts.startIndex += 5;    }, this.opts.delay);    setTimeout(() => {      this.stopAnim();    }, this.opts.duration);}SearchAnim.prototype.stopAnim = function() {    if (this.timer != null) {      clearInterval(this.timer);    }}SearchAnim.DEFAULTS = {    duration : 60000,    delay : 200,    direction : true,    startIndex : 0,    endIndex : 360}new SearchAnim({  elemId : "wait-icon",  delay : 20,});</script><body></body></html>

使用本站HTML/CSS/JS在線運行測試工具http://tools.VeVB.COm/code/HtmlJsRun,可得到如下測試運行效果:

 

更多關(guān)于JavaScript相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《JavaScript動畫特效與技巧匯總》、《JavaScript頁面元素操作技巧總結(jié)》、《JavaScript運動效果與技巧匯總》、《JavaScript圖形繪制技巧總結(jié)》、《JavaScript切換特效與技巧總結(jié)》、《JavaScript錯誤與調(diào)試技巧總結(jié)》、《JavaScript數(shù)據(jù)結(jié)構(gòu)與算法技巧總結(jié)》及《JavaScript數(shù)學(xué)運算用法總結(jié)

希望本文所述對大家JavaScript程序設(shè)計有所幫助。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 吴桥县| 宜城市| 永胜县| 巨鹿县| 琼结县| 巴东县| 上蔡县| 那曲县| 大渡口区| 疏勒县| 渝中区| 弥渡县| 调兵山市| 丹巴县| 万安县| 尖扎县| 册亨县| 崇明县| 固安县| 宝兴县| 东乡县| 汝阳县| 远安县| 福安市| 兰考县| 读书| 无极县| 洞头县| 伊川县| 泗洪县| 潞西市| 承德市| 英超| 雷州市| 萨嘎县| 中牟县| 大厂| 金川县| 尼勒克县| 涡阳县| 延庆县|