網頁中引入網易雲音樂,貼邊隱藏
阿新 • • 發佈:2019-01-01
不廢話,直接上程式碼
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>網易雲音樂</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" >
<script src="../../static/jsonFormater/jquery-1.7.2.min.js" type="text/javascript"></script>
<style type="text/css">
body {
margin: 0;
padding: 0;
}
#music-163 {
z-index: 10;
width: 330px;
height : 450px;
position: fixed;
left: -330px;
top: 100px;
}
#music-163 span {
width: 50px;
height: 50px;
background-color: #aeabc1;
position: absolute;
left: 330px;
top: 0;
border-radius : 2px;
}
</style>
<script type="text/javascript">
$(function () {
var mDiv = $('#music-163');
mDiv.mouseover(function () {
startMove(0);
});
mDiv.mouseout(function () {
startMove(-330);
});
});
var timer = null;
function startMove(target) {
clearInterval(timer);
var mDiv = $('#music-163');
timer = setInterval(function () {
// 越靠近目標值速度越小
var speed = (target - mDiv.offset().left) / 20;
//向右移動速度為正數,向左為負數,將speed取整,顯示不完全
speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);
if (mDiv.offset().left === target) {
clearInterval(timer);
} else {
mDiv.css('left',mDiv.offset().left + speed + "px")
}
}, 10)
}
</script>
</head>
<body>
<div id="music-163">
<object width="330" height="450"
data="http://music.163.com/style/swf/widget.swf?sid=2232237850&type=0&auto=0&width=310&height=430"
type="application/x-shockwave-flash"></object>
<span id="music">
<img height="100%" width="100%" src="../../static/home/images/avatar.jpg" alt=""/>
</span>
</div>
</body>
</html>
網易雲外掛有兩種引入方式
第一種 iframe方式引入
優點:可以自己調整外掛的高度、寬度
缺點:很多部落格網站不支援嵌入iframe
<iframe frameborder="no" border="0" marginwidth="0"
marginheight="0" width=330 height=450
src="http://music.163.com/outchain/player?type=0&id=815573174&auto=0&height=430">
</iframe>
顯示效果
第二種,瀏覽器需要安裝Flash外掛
優點:可以適用大部分的部落格,如網易、新浪部落格等
缺點:無法自己調整外掛的高度、寬度
<object width="330" height="450" data="http://music.163.com/style/swf/widget.swf?sid=815573174&type=0&auto=0&width=310&height=430" type="application/x-shockwave-flash">
</object>
顯示效果
引數設定:
type : 型別(0:單曲、2:歌單)
id/sid:歌曲id
auto:0/1
0 表示開啟網頁的時候不自動播放;
1表示開啟網頁的時候自動播放。
覺得有幫助就點個贊吧