此代码适用于soundcloud的小部件以允许远程文本按钮,我试图使其作为一个图像按钮的遥控器工作,根据所选的类别,具有不同的图片暂停/播放,而不是txt_on_pause txt_on_play。关于如何切换的任何想法?
$(function () {
var widgetIframe = document.getElementById('sc-widget'),
widget = SC.Widget(widgetIframe),
txt_on_pause = '¡Escuchar música!',
txt_on_play = 'Escuchando algo de música... (click para pausar)';
widget.bind(SC.Widget.Events.READY, function () {
$(".sc-toggle").html(txt_on_pause);
});
widget.bind(SC.Widget.Events.PAUSE, function () {
$(".sc-toggle").html(txt_on_pause);
});
widget.bind(SC.Widget.Events.PLAY, function () {
$(".sc-toggle").html(txt_on_play);
});
$(".sc-toggle").click(function (e) {
e.preventDefault();
widget.toggle();
});
});
答案 0 :(得分:0)
使用addClass
和removeClass
功能应该有效。
$(function () {
var widgetIframe = document.getElementById('sc-widget'),
widget = SC.Widget(widgetIframe),
txt_on_pause = '¡Escuchar música!',
txt_on_play = 'Escuchando algo de música... (click para pausar)';
widget.bind(SC.Widget.Events.READY, function () {
$(".sc-toggle")
.removeClass('pause')
.removeClass('play')
.addClass('ready'));
});
widget.bind(SC.Widget.Events.PAUSE, function () {
$(".sc-toggle")
.removeClass('play')
.removeClass('ready')
.addClass('pause');
});
widget.bind(SC.Widget.Events.PLAY, function () {
$(".sc-toggle")
.removeClass('pause')
.removeClass('ready')
.addClass('play');
});
$(".sc-toggle").click(function (e) {
e.preventDefault();
widget.toggle();
});
});