我想使用html5小部件+它的api(http://developers.soundcloud.com/docs/html5-widget) 我的问题:可以通过CSS设置小部件吗? FireBug会在播放器加载后显示样式信息,我想知道是否可以更改这些样式?
答案 0 :(得分:5)
不,这是不可能的。小部件在iframe中插入到页面中,我认为不可能从外部更改iframe内的样式。唯一能满足的“造型”是通过“color”url参数改变按钮和波形的颜色。
例如,这是一个用户的声音小部件,带有漂亮的粉红色按钮和波形高亮:
这是为了易读性而重新格式化的网址:
http://w.soundcloud.com/player/
?url=http%3A%2F%2Fapi.soundcloud.com%2Fusers%2F2
&show_artwork=true
&show_comments=false
&color=ff00ff <-----
&show_playcount=false
&liking=false
答案 1 :(得分:1)
那个人使用SoundCloud API,一些JavaScript和CSS来做到这一点:
http://codepen.io/nickcolley/pen/uoCIy
$(document).ready(function(){
var player = SC.Widget($('iframe.sc-widget')[0]);
var pOffset = $('.player').offset();
var pWidth = $('.player').width();
var scrub;
player.bind(SC.Widget.Events.READY, function() {
setInfo();
player.play();
}); //Set info on load
player.bind(SC.Widget.Events.PLAY_PROGRESS, function(e) {
if( e.relativePosition < 0.003 ) { setInfo(); }
//Event listener when track is playing
$('.position').css('width', ( e.relativePosition*100)+"%");
});
$('.player').mousemove(function(e){ //Get position of mouse for scrubbing
scrub = (e.pageX-pOffset.left);
});
$(document).on('keydown', function(e){
switch(e.keyCode){
case 32:
player.toggle();
break;
case 39:
player.next();
break;
case 37:
player.prev();
break;
}
});
$('.player').click(function(){ //Use the position to seek when clicked
$('.position').css('width',scrub+"px");
var seek = player.duration*(scrub/pWidth);
//Seeking to the start would be a previous?
if ( seek < player.duration * .05 ) {
player.prev();
} else if ( seek > player.duration * .99 ) {
player.next();
} else {
player.seekTo(seek);
}
});
function setInfo() {
player.getCurrentSound(function(song) {
console.log(song);
$('.waveform').css('background-image', "url('" + song.waveform_url + "')");
$('.player').css('background-image', "url('" + song.artwork_url.replace('-large', '-t500x500') + "')");
var info = song.title;
$('.info').html(info);
player.current = song;
});
player.getDuration(function(value){
player.duration = value;
});
player.isPaused(function(bool){
player.getPaused = bool;
});
}
});