关闭模态时停止声音云。有HTML或JQuery解决方案吗?我试过这个。但是我无法让它发挥作用。我的代码有什么东西可以忽略吗?似乎变量搞乱了代码,但我不知道为什么......
代码:
<div class = "modal fade" id = "seeyou" role= "dialoge">
<div class = "modal-dialog">
<div class = "modal-content">
<div class= "modal-header">
<h4>GUEST LIST</h4>
<div id = "video">
<iframe width="100%" height="166" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/199607357&color=ff5500&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false"></iframe>
</div>
<div class = "modal-footer">
<a class = "btn btn-default" data-dismiss = "modal">CLOSE</a>
</div>
</div>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
<script src="https://w.soundcloud.com/player/api.js"></script>
<script src="copy.js"></script>
</body>
</html>
$(document).ready(function() {
$('.box-toggle3').hide();
$('.box-toggle1').hide();
$('.box-toggle2').hide();
var iframeElement = $('#video > iframe')[0];
var scPlayer = SC.Widget('iframeElement');
$('#seeyou').on('hidden.bs.modal', function () {
scPlayer.pause();
});
$('#new-releases').click(function() {
$('#box').removeClass('box-reg');
$('#box').addClass('box-zoom');
$('.box-toggle1').fadeOut(200);
$('.box-toggle3').fadeOut(250);
$('.box-toggle2').fadeOut(250);
$('.box-toggle').fadeOut(250);
$('.box-toggle1').fadeIn(2500);
});
$('#concerts').click(function() {
$('.box-toggle3').fadeOut(250);
$('.box-toggle2').fadeOut(250);
$('.box-toggle1').fadeOut(200);
$('.box-toggle').fadeOut(250);
$('#box').removeClass('box-zoom');
$('#box').addClass('box-reg');
$('.box-toggle2').fadeIn(2500);
});
$('#playlists').click(function() {
$('.box-toggle3').fadeOut(250);
$('.box-toggle2').fadeOut(250);
$('.box-toggle1').fadeOut(200);
$('.box-toggle').fadeOut(250);
$('#box').removeClass('box-zoom');
$('#box').addClass('box-reg');
$('.box-toggle3').fadeIn(2500);
});
$('#news').click(function() {
$('.box-toggle').fadeOut(250);
$('.box-toggle3').fadeOut(250);
$('.box-toggle2').fadeOut(250);
$('.box-toggle1').fadeOut(200);
$('#box').removeClass('box-zoom');
$('#box').addClass('box-reg');
$('.box-toggle').fadeIn(2500);
});
$('#news2').click(function() {
$('.box-toggle3').fadeOut(250);
$('.box-toggle2').fadeOut(250);
$('.box-toggle1').fadeOut(200);
$('.box-toggle').fadeOut(250);
$('#box').removeClass('box-zoom');
$('#box').addClass('box-reg');
$('.box-toggle2').fadeIn(1500);
});
$('#news3').click(function() {
$('#box').removeClass('box-reg');
$('#box').addClass('box-zoom');
$('.box-toggle1').fadeOut(200);
$('.box-toggle3').fadeOut(250);
$('.box-toggle2').fadeOut(250);
$('.box-toggle').fadeOut(250);
$('.box-toggle1').fadeIn(1500);
});
});
答案 0 :(得分:3)
SoundCloud's public API 可用于控制播放器。
var iframeElement = $('#video > iframe')[0]; // catches the iframe element
var scPlayer = SC.Widget(iframeElement); // wraps with SoundClouds api
$('#myModal1').on('hidden.bs.modal', function () {
scPlayer.pause(); // pause the player when the modal window is closed.
})
答案 1 :(得分:0)
我终于开始工作了。我不得不改变IFRAMEELEMENT的变量,我可以调用该函数。非常感谢您的帮助!
<div class = "modal fade" id = "seeyou" role= "dialoge">
<div class = "modal-dialog">
<div class = "modal-content">
<div class= "modal-header">
<h4>GUEST LIST</h4>
<div id = "video">
<iframe id = "sc-widget" width="100%" height="166" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/199607357&color=ff5500&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false"></iframe>
</div>
<div class = "modal-footer">
<a id = "stopSound" class = "btn btn-default" data-dismiss = "modal">CLOSE</a>
</div>
</div>
</div>
</div>
</div>
var widget1 = SC.Widget("sc-widget");
$("#stopSound").click(function() {
widget1.pause()
});
$('#seeyou').on('hidden.bs.modal', function () {
widget1.pause();
});