2015-04-28 62 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 –