From 4f43908198eb6a168845b77bd26998a66a39504a Mon Sep 17 00:00:00 2001 From: DIYgod Date: Sun, 15 Nov 2015 23:59:59 +0800 Subject: [PATCH] icon compatibility --- APlayer.css | 55 +++++++++--------- APlayer.js | 39 ++++++++----- README.md | 4 +- font/{fontello.eot => aplayer-fontello.eot} | Bin font/{fontello.svg => aplayer-fontello.svg} | 0 font/{fontello.ttf => aplayer-fontello.ttf} | Bin font/{fontello.woff => aplayer-fontello.woff} | Bin 7 files changed, 55 insertions(+), 43 deletions(-) rename font/{fontello.eot => aplayer-fontello.eot} (100%) rename font/{fontello.svg => aplayer-fontello.svg} (100%) rename font/{fontello.ttf => aplayer-fontello.ttf} (100%) rename font/{fontello.woff => aplayer-fontello.woff} (100%) diff --git a/APlayer.css b/APlayer.css index 542166e..719a54f 100644 --- a/APlayer.css +++ b/APlayer.css @@ -1,16 +1,16 @@ @font-face { - font-family: 'fontello'; - src: url('font/fontello.eot?72550380'); - src: url('font/fontello.eot?72550380#iefix') format('embedded-opentype'), - url('font/fontello.woff?72550380') format('woff'), - url('font/fontello.ttf?72550380') format('truetype'), - url('font/fontello.svg?72550380#fontello') format('svg'); + font-family: 'aplayer-fontello'; + src: url('font/aplayer-fontello.eot?72550380'); + src: url('font/aplayer-fontello.eot?72550380#iefix') format('embedded-opentype'), + url('font/aplayer-fontello.woff?72550380') format('woff'), + url('font/aplayer-fontello.ttf?72550380') format('truetype'), + url('font/aplayer-fontello.svg?72550380#fontello') format('svg'); font-weight: normal; font-style: normal; } -[class^="icon-"]:before, [class*=" icon-"]:before { - font-family: "fontello"; +.aplayer [class^="aplayer-icon-"]:before, [class*=" aplayer-icon-"]:before { + font-family: "aplayer-fontello"; font-style: normal; font-weight: normal; speak: none; @@ -25,43 +25,43 @@ -moz-osx-font-smoothing: grayscale; } -.icon-weibo:before { +.aplayer .aplayer-icon-weibo:before { content: '\e805'; } -.icon-play:before { +.aplayer .aplayer-icon-play:before { content: '\e806'; } -.icon-pause:before { +.aplayer .aplayer-icon-pause:before { content: '\e807'; } -.icon-to-start:before { +.aplayer .aplayer-icon-to-start:before { content: '\e808'; } -.icon-to-end:before { +.aplayer .aplayer-icon-to-end:before { content: '\e809'; } -.icon-list:before { +.aplayer .aplayer-icon-list:before { content: '\e80a'; } -.icon-menu:before { +.aplayer .aplayer-icon-menu:before { content: '\e80b'; } -.icon-volume-off:before { +.aplayer .aplayer-icon-volume-off:before { content: '\e800'; } -.icon-volume-down:before { +.aplayer .aplayer-icon-volume-down:before { content: '\e801'; } -.icon-volume-up:before { +.aplayer .aplayer-icon-volume-up:before { content: '\e802'; } @@ -78,7 +78,7 @@ } .aplayer span { - cursor: default; + cursor: default !important; } .aplayer .aplayer-pic { @@ -131,7 +131,7 @@ margin: -15px 0 0 -15px; } -.aplayer .aplayer-play .icon-play { +.aplayer .aplayer-play .aplayer-icon-play { position: absolute; top: 2px; left: 4px; @@ -146,9 +146,9 @@ right: 4px; } -.aplayer .aplayer-pause .icon-pause { +.aplayer .aplayer-pause .aplayer-icon-pause { position: absolute; - top: 2px; + top: 1px; left: 2px; font-size: 12px; } @@ -159,6 +159,9 @@ } .aplayer .aplayer-music { + overflow: hidden; + white-space: nowrap; + text-overflow: ellipsis; margin-bottom: 17px; } @@ -172,7 +175,7 @@ } .aplayer .aplayer-music a { - margin-left: 20px; + margin-right: 7px; font-size: 14px; color: #000; } @@ -194,7 +197,7 @@ height: 2px; width: 100%; background: #cdcdcd; - cursor: pointer; + cursor: pointer !important; } .aplayer .aplayer-loaded { @@ -227,7 +230,7 @@ border: 1px solid #b7daff; border-radius: 50%; background: #fff; - cursor: pointer; + cursor: pointer !important; } .aplayer .aplayer-thumb:hover { @@ -251,7 +254,7 @@ .aplayer .aplayer-volume-wrap { display: inline-block; margin-left: 7px; - cursor: pointer; + cursor: pointer !important; } .aplayer .aplayer-volume-wrap:hover .aplayer-volume-bar-wrap { diff --git a/APlayer.js b/APlayer.js index dc10ba9..8938d71 100644 --- a/APlayer.js +++ b/APlayer.js @@ -8,17 +8,17 @@ APlayer.prototype.init = function () { + '
' + '' + '
' - + '' + + '' + '
' + '
' - + '' + + '' + '
' + '
' + '
' + '
' + + '' + '' + this.option.music.title + '' + ' - ' + this.option.music.author + '' - + '' + '
' + '
' + '
' @@ -32,7 +32,7 @@ APlayer.prototype.init = function () { + '' + ' - 00:00 / 00:00' + '
' - + '' + + '' + '
' + '
' + '
' @@ -84,7 +84,7 @@ APlayer.prototype.init = function () { this.bar.addEventListener('click', function (event) { var e = event || window.event; barWidth = _self.bar.clientWidth; - var percentage = (e.clientX - getElementLeft(_self.bar)) / barWidth; + var percentage = (e.clientX - getElementViewLeft(_self.bar)) / barWidth; _self.updateBar.call(_self, 'played', percentage, 'width'); _self.option.element.getElementsByClassName('aplayer-ptime')[0].innerHTML = _self.secondToTime(percentage * _self.audio.duration); _self.audio.currentTime = parseFloat(_self.playedBar.style.width) / 100 * _self.audio.duration; @@ -99,7 +99,7 @@ APlayer.prototype.init = function () { function thumbMove (event) { var e = event || window.event; - var percentage = (e.clientX - getElementLeft(_self.bar)) / barWidth; + var percentage = (e.clientX - getElementViewLeft(_self.bar)) / barWidth; percentage = percentage > 0 ? percentage : 0; percentage = percentage < 1 ? percentage : 1; _self.updateBar.call(_self, 'played', percentage, 'width'); @@ -124,49 +124,56 @@ APlayer.prototype.init = function () { var barHeight = 35; this.option.element.getElementsByClassName('aplayer-volume-bar-wrap')[0].addEventListener('click', function (event) { var e = event || window.event; - var percentage = (barHeight - e.clientY + getElementTop(volumeBarWrap)) / barHeight; + var percentage = (barHeight - e.clientY + getElementViewTop(volumeBarWrap)) / barHeight; percentage = percentage > 0 ? percentage : 0; percentage = percentage < 1 ? percentage : 1; _self.updateBar.call(_self, 'volume', percentage, 'height'); _self.audio.volume = percentage; + if (_self.audio.muted) { + _self.audio.muted = false; + } if (percentage === 1) { - volumeicon.className = 'demo-icon icon-volume-up'; + volumeicon.className = 'demo-icon aplayer-icon-volume-up'; } else { - volumeicon.className = 'demo-icon icon-volume-down'; + volumeicon.className = 'demo-icon aplayer-icon-volume-down'; } }); volumeicon.addEventListener('click', function () { if (_self.audio.muted) { _self.audio.muted = false; - volumeicon.className = _self.audio.volume === 1 ? 'demo-icon icon-volume-up' : 'demo-icon icon-volume-down'; + volumeicon.className = _self.audio.volume === 1 ? 'demo-icon aplayer-icon-volume-up' : 'demo-icon aplayer-icon-volume-down'; _self.updateBar.call(_self, 'volume', _self.audio.volume, 'height'); } else { _self.audio.muted = true; - volumeicon.className = 'demo-icon icon-volume-off'; + volumeicon.className = 'demo-icon aplayer-icon-volume-off'; _self.updateBar.call(_self, 'volume', 0, 'height'); } }); // 获取元素相对窗口位置 - function getElementLeft (element){ + function getElementViewLeft (element) { var actualLeft = element.offsetLeft; var current = element.offsetParent; + var elementScrollLeft; while (current !== null){ actualLeft += current.offsetLeft; current = current.offsetParent; } - return actualLeft; + elementScrollLeft = document.body.scrollLeft + document.documentElement.scrollLeft; + return actualLeft - elementScrollLeft; } - function getElementTop(element){ + function getElementViewTop (element) { var actualTop = element.offsetTop; var current = element.offsetParent; + var elementScrollTop; while (current !== null){ - actualTop += current.offsetTop; + actualTop += current. offsetTop; current = current.offsetParent; } - return actualTop; + elementScrollTop = document.body.scrollTop + document.documentElement.scrollTop; + return actualTop - elementScrollTop; } // 自动播放 diff --git a/README.md b/README.md index c364d47..fdb5462 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,9 @@ API - [x] 播放进度拖拽控制 - [x] 音量控制 - [x] 分享到微博 -- [ ] 错误处理 +- [ ] 加载样式及错误处理 +- [ ] 窄样式 +- [ ] 宽度高度自定义 - [ ] 播放列表 - [ ] 歌词展示 diff --git a/font/fontello.eot b/font/aplayer-fontello.eot similarity index 100% rename from font/fontello.eot rename to font/aplayer-fontello.eot diff --git a/font/fontello.svg b/font/aplayer-fontello.svg similarity index 100% rename from font/fontello.svg rename to font/aplayer-fontello.svg diff --git a/font/fontello.ttf b/font/aplayer-fontello.ttf similarity index 100% rename from font/fontello.ttf rename to font/aplayer-fontello.ttf diff --git a/font/fontello.woff b/font/aplayer-fontello.woff similarity index 100% rename from font/fontello.woff rename to font/aplayer-fontello.woff