2015-04-28 23 views
0

这里的网站有一个音乐播放器http://www.numberonedesigns.com/ubermusic.com/ ...当随机突出显示的下一个按钮不会随机化正确。它总是会回到播放列表中的第一首歌曲,然后随机播放下一个..这是可变代码。我试着弄了一会儿,但决定我需要一些帮助网站的Java脚本变化

$next.click(function(){ 
     var num = 0; 
     $.cookie('plate_time', 1); 
     if($random.hasClass('active')){ 
      while(num == $audio.currentTrack){num = Math.floor(Math.random() * (opt.playlist.length));} 
     }else{ 
      num = $audio.currentTrack - 1; 
     } 

     $audio.loadTrack(num); 
    }); 

    $playlist.on('click', '.track', function(){ 
     $audio.loadTrack($(this).attr('rel')); 
    }); 

    $prev.click(function(){ 
     var num = 0; 
     $.cookie('plate_time', 0); 
     if($random.hasClass('active')){ 
      while(num == $audio.currentTrack){num = Math.floor(Math.random() * (opt.playlist.length));} 
     }else{ 
      num = $audio.currentTrack - 1; 
     } 

     $audio.loadTrack(num); 
    }); 

回答

1

既然你问得这么好:

$next.click(function(){ 
    var num = Math.floor(Math.random() * (opt.playlist.length)); 
    //Set the random number here. 
    $.cookie('plate_time', 1); 
    if($random.hasClass('active')){ 
     while(num == $audio.currentTrack){num = Math.floor(Math.random() * (opt.playlist.length));} 
     // leaving it here JIC you get the same track. 
    }else{ 
     num = $audio.currentTrack - 1; 
    // cos the ordering still works here if not on random. 
    } 

    $audio.loadTrack(num); 
}); 

$playlist.on('click', '.track', function(){ 
    $audio.loadTrack($(this).attr('rel')); 
}); 

$prev.click(function(){ 
    var num = Math.floor(Math.random() * (opt.playlist.length)); 
    $.cookie('plate_time', 0); 
    if($random.hasClass('active')){ 
     while(num == $audio.currentTrack){num = Math.floor(Math.random() * (opt.playlist.length));} 
    }else{ 
     num = $audio.currentTrack - 1; 
    } 

    $audio.loadTrack(num); 
}); 
+0

这就是诀窍!我想是时候真正开始学习一些JS,而不是依赖其他人的插件。你这个人!谢谢技术混沌 –

1

你在功能开始时将num设置为0。 这意味着当当前曲目为播放列表[0]时,该功能被触发,但是当当前曲目不是播放列表[0]但num设置为0时,不调用随机播放并播放播放列表[0]再次。 while检查会使您在开始时将num设置为0。

+0

这就是我的想法。这是一个购买的插件... 我该如何处理0?或者那一行字符串?我尝试删除它,将0定义为无限制,并将其定义为其他事物的完整线索。我难住lol –