ここで 2 つの部分についてお役に立てれば幸いです。
1 つは、jQuery のベスト プラクティスに関して、コードをより効率的に短縮/効率化する方法を理解するのに役立つことです。
もう 1 つはコードを拡張することです。クリックして div をスライドさせます (animate/left を使用) が、ページ上でこれを何度も繰り返しています。私が求めているのは、divがクリックされてスライドアウトし、別のdivがクリックされた場合、開いているdivがスライドして戻り、新しいdivがスライドアウトすることです。等々。それが理にかなっていることを願っています。
jQuery
$('.each-brew.ale').toggle(function() {
$('.each-brew-content.ale').animate({ left: '0' }, 1000);
$('.each-brew-content.ale').css('display','block');
}, function() {
$('.each-brew-content.ale').animate({ left: '-100%' }, 1000);
$('.each-brew-content.ale').css('display','none');
});
$('.each-brew.bramling').toggle(function() {
$('.each-brew-content.bramling').animate({ left: '0' }, 1000);
$('.each-brew-content.bramling').css('display','block');
}, function() {
$('.each-brew-content.bramling').animate({ left: '-100%' }, 1000);
$('.each-brew-content.bramling').css('display','none');
});
$('.each-brew.bullet').toggle(function() {
$('.each-brew-content.bullet').animate({ left: '0' }, 1000);
$('.each-brew-content.bullet').css('display','block');
}, function() {
$('.each-brew-content.bullet').animate({ left: '-100%' }, 1000);
$('.each-brew-content.bullet').css('display','none');
});
$('.each-brew.miami-weisse').toggle(function() {
$('.each-brew-content.miami-weisse').animate({ left: '0' }, 1000);
$('.each-brew-content.miami-weisse').css('display','block');
}, function() {
$('.each-brew-content.miami-weisse').animate({ left: '-100%' }, 1000);
$('.each-brew-content.miami-weisse').css('display','none');
});
HTML
<div class="row">
<div class="four columns first-margin-offset">
<div class="each-brew-container delay-1">
<div class="each-brew ale">
<span class="each-brew-title">Ale<span class="each-brew-description">South Pacific Best Bitter</span></span>
</div>
<div class="each-brew-separator"></div>
<div class="each-brew bramling">
<span class="each-brew-title">Bramling<span class="each-brew-description">English Hop Golden Ale</span></span>
</div>
<div class="each-brew-separator"></div>
<div class="each-brew bullet">
<span class="each-brew-title">Bullet<span class="each-brew-description">Original IPA</span></span>
</div>
<div class="each-brew-separator"></div>
<div class="each-brew miami-weisse">
<span class="each-brew-title">Miami Weisse<span class="each-brew-description">American Hopped Wheat Beer</span></span>
</div>
<div class="each-brew-separator"></div>
</div>
</div>
<div class="each-brew-content ale">
<div class="three columns first-margin-offset">
<div class="each-brew-image"><img width="327" height="511" src="ale-clip-01.png" class="attachment-brew-standard" alt="ale-clip-01" /></div> </div>
<div class="three columns first-margin-offset">
<div class="default-content-area content-area ale-content">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.</p>
</div>
</div>
</div>
<div class="each-brew-content bramling">
<div class="three columns first-margin-offset">
<div class="each-brew-image"><img width="326" height="511" src="bramling.png" class="attachment-brew-standard" alt="bramling" /></div> </div>
<div class="three columns first-margin-offset">
<div class="default-content-area content-area bramling-content">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.</p>
</div>
</div>
</div>
<div class="each-brew-content bullet">
<div class="three columns first-margin-offset">
<div class="each-brew-image"><img width="327" height="511" src="bullet.png" class="attachment-brew-standard" alt="bullet" /></div> </div>
<div class="three columns first-margin-offset">
<div class="default-content-area content-area bullet-content">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.</p>
</div>
</div>
</div>
<div class="each-brew-content miami-weisse">
<div class="three columns first-margin-offset">
<div class="each-brew-image"><img width="326" height="511" src="miami-weisse.png" class="attachment-brew-standard" alt="miami-weisse" /></div> </div>
<div class="three columns first-margin-offset">
<div class="default-content-area content-area miami-weisse-content">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.</p>
</div>
</div>
</div>