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

首頁 > 編程 > JavaScript > 正文

基于jQuery實現歌詞滾動版音樂播放器的代碼

2019-11-20 08:59:02
字體:
來源:轉載
供稿:網友

先給大家看下效果圖,感興趣的朋友可以參考實現代碼


核心代碼如下所示:

$.ajax({url: "/music/music.txt",type: "get",success: function(data) {data = jQuery.parseJSON(data);var length = data.length;var now=0;for (i = 0; i < length; i++) {$("#musicText li").eq(i).after("<li>" + data[i].text + "</li>")}var player = {playButton: $(".play"),songText: $(".musicText"),state: 0,//0播放,1暫停audio: $("#audio").get(0),bind: function() {//綁定按鈕//播放或暫停console.log($.type(this))console.log($.type(this))var obj = this;this.playButton.click(function() {obj.changeState(obj.state ? 0 : 1);});//設置聲音$("#voice").click(function(ex) {var percent = (ex.clientX - $(this).offset().left) / $(this).width();obj.setVoice(percent);});//默認聲音 0.8 obj.setVoice(1.0);//靜音$("#voiceOP").click(function() {if (obj.muted) {$(this).removeClass("muted");obj.audio.muted = false;obj.muted = false;} else {$(this).addClass("muted");obj.audio.muted = true;obj.muted = true;}});//設置進度$("#MusicProgress").click(function(ex) {var percent = (ex.clientX - $(this).offset().left) / $(this).width();obj.setProgress(percent, false);});//上一首$("#prev").click(function() {obj.nowIndex--;if (obj.nowIndex < 0) obj.nowIndex = obj.list.length - 1;obj.playSing(obj.nowIndex);});//下一首$("#next").click(function() {obj.nowIndex++;if (obj.nowIndex >= obj.list.length) obj.nowIndex = 0;obj.playSing(obj.nowIndex);player.audio.play();});//綁定事件 - 播放時間改變this.audio.ontimeupdate = function() {obj.timeChange();}//播放結束this.audio.onended = function() {obj.singEnd();}},//切換播放狀態changeState: function(_state) {this.state = _state;if (!this.state) {this.playButton.removeClass("pause").addClass("play");this.pause();} else {this.playButton.removeClass("play").addClass("pause");this.play();}},//播放play: function() {this.audio.play();},//暫停pause: function() {this.audio.pause();},timeChange: function() {var nowSec = Math.floor(this.audio.currentTime);console.log(nowSec)console.log(data[now].time)if(nowSec>data[now].time){now = now + 1;console.log(now)$("#musicText li").eq(now).addClass("active").siblings("li").removeClass("active");$("#musicText").css("top",-(24*now)+138)}var totalSec = Math.floor(this.audio.duration);//當前進度顯示var secTip = secFormat(nowSec) + "/" + secFormat(totalSec);if (secTip.length == 11) $("#secTip").html(secTip);this.setProgress(nowSec / totalSec, true);},setVoice: function(percent) {$("#voice").children(".bar").css("width", percent * 100 + "%");$("#voice").children("a").css("left", percent * 100 + "%");this.audio.volume = percent;},setProgress: function(percent, justCss) {$("#MusicProgress").children(".bar").css("width", percent * 100 + "%");$("#MusicProgress").children("a").css("left", percent * 100 + "%");if (!justCss) this.audio.currentTime = this.audio.duration * percent;},singEnd: function() {if (this.style == 0) {this.nowIndex++;if (this.nowIndex >= this.list.length) this.nowIndex = 0;this.playSing(this.nowIndex);} else {var index = Math.floor(Math.random() * (this.list.length + 1)) - 1;index = index < 0 ? 0 : index;index = index >= this.list.length ? (this.list.length - 1) : index;this.playSing(index);this.nowIndex = index;}},};player.bind();function secFormat(num) {var m = Math.floor(num / 60);var s = Math.floor(num % 60);return makeFormat(m) + ":" + makeFormat(s);function makeFormat(n) {if (n >= 10) return n;else {return "0" + n;}}}}})

然后這里的代碼是alpha0.0.1版的,一直在升級ing.

以上所述是小編給大家介紹的基于jQuery實現歌詞滾動版音樂播放器的代碼,希望對大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會及時回復大家的。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 隆德县| 图片| 鲁山县| 铜梁县| 大宁县| 太湖县| 涞源县| 岳池县| 公主岭市| 惠东县| 广水市| 济阳县| 六盘水市| 封丘县| 祁门县| 吉木乃县| 惠水县| 昌江| 嘉荫县| 玛多县| 潮州市| 苍溪县| 湖州市| 昭觉县| 南通市| 武威市| 综艺| 开阳县| 双流县| 吉林省| 百色市| 南宁市| 麻城市| 常德市| 绍兴县| 陆川县| 文昌市| 怀化市| 理塘县| 论坛| 黎城县|