diff --git a/www/js/beauty.js b/www/js/beauty.js index 9e835cb..339d890 100644 --- a/www/js/beauty.js +++ b/www/js/beauty.js @@ -267,6 +267,15 @@ $('.cleanCacheJS').click(function () { if ($('#music_main').length > 0) { var musicState = 0; $('#music_main').get(0).volume = 0.5; // 控制音量 + $('#music_main').one('canplay', function() { + var cookieKey = 'audio_current_time'; + var currentTime = Cookies.get(cookieKey); + if (currentTime > 0) { + this.currentTime = currentTime; + $('.musicJS').addClass('music_put'); + } + }); + $('.musicJS').click(function () { if (musicState == 0) { $('#music_main').get(0).play(); @@ -285,6 +294,22 @@ if ($('#music_main').length > 0) { $('.musicJS').addClass('music_put'); musicState = 1; }); + + $(window).on('beforeunload', function() { + $('#music_main').get(0).volume = 0.2; // 减小音量 + var currentTime = $('#music_main').get(0).currentTime; + var cookieKey = 'audio_current_time'; + Cookies.set(cookieKey, currentTime, { expires: 1 }); + }); + + $(document.body).click(function(evt) { + var elA = $(evt.target).parents('a'); + if (elA.length > 0 && elA.attr('target') == '_blank') { //点击视频暂停音乐 + $('#music_main').get(0).pause(); + $('.musicJS').removeClass('music_put'); + musicState = 0; + } + }); } //二维码显示