ここにフィドルがあります:
ユーザーが再生ボタンをクリックすると、下の画像のようにレコード針がレコードに回転するようにしたい(フィドルを参照)
針の配置は必ずしも最終的なものではなく、右上隅に配置したい場合があります (そのために必要な画像と下部の css を含めました)。
現在、再生をクリックすると (フィドルを参照し、レコード カバーの 1 つにカーソルを合わせ、再生をクリックします)、レコードの針が左から入り、同じレコードで停止をクリックすると、左に戻ります。再生中のレコードを停止する前に別のレコードの再生をクリックすると、同じ場所にとどまります。
再生ボタンをクリックしてから回転しない限り、常に表示されますが、レコードには表示されない下の画像のようにしたいと思います。次に、現在再生中の別のレコードで再生をクリックすると、その変化のようにシフト/移動します。もちろん、停止をクリックするとオフレコになります。
これが私の現在のスクリプトです:
$(function(){
var station = $('.player-station'),
record = $('.record2:first'),
playBtns = $('.play'),
info = $('.nprecinfo');
var isPlaying = false;
playBtns.click(function()
{
var btn = $(this);
if(btn.text() == 'STOP')
{
btn.text('PLAY');
record.css({'-webkit-animation-play-state': 'paused',
'-moz-animation-play-state': 'paused'});
$('#needle').show().animate({"left": "-=120px"}, "slow");
isPlaying = false;
return;
};
playBtns.text('PLAY');
var album = btn.closest('.album');
station.text(album.find('h3').text());
info.text(album.find('.recordinfo').text());
record.css({'-webkit-animation-play-state': 'running',
'-moz-animation-play-state': 'running'});
if (isPlaying == false)
{
$('#needle').show().animate({"left": "+=120px"}, "slow");
isPlaying = true;
}
$('#lrvinyl').css("background-image","url("+btn.attr('rel')+")");
$('#lrvinyl').hide().fadeIn();
btn.text('STOP');
});
});
レコード針の現在の CSS は次のとおりです。
#needle {
background-image:url(http://benlevywebdesign.com/somafm/images/recordneedle2.png);
background-repeat: no-repeat;
width:220px;
height:220px;
position:absolute;
left:-115px;
top:185px;
z-index:10;
overflow:hidden;
}
針を右上隅に配置する場合は、そのためのフィドルで使用する画像と css を次に示します。
(.record2)
レコードを少し移動する必要があるかもしれないので、css をleft:-4px;
#needle {
background-image:url(http://benlevywebdesign.com/somafm/images/recordneedle4.png);
background-repeat: no-repeat;
width:220px;
height:220px;
position:absolute;
left:205px;
top:10px;
z-index:10;
overflow:hidden;
}