안녕하세요, 저는 프로그래밍 jQuery에 익숙하지 않습니다. 빠른 코드 스 니펫을 사용하여 나를 테스트 해줄 사람을 사랑합니다.jQuery : 슬라이드 토글 || 코드 최적화?
나는 그것이 잘 작동한다고 생각한다. 그러나 나는 그것을 다루는 가장 좋은 방법인지는 모른다.
작업 예 : 여기 http://jsfiddle.net/zWnLv/29/
//hide wrapper at document ready
$('#newsbox_content_wrapper').hide();
//toggle visiblility of newsbox and slide down to scroll window to newsbox
$('.newsbox_toggle').bind('click', function() {
//define speed for effect
var $speed = 400;
//check to see if the class 'open' exists then run
if ($('.newsbox_toggle').hasClass('open')) {
//scroll to the top of the newsbox
$('html, body').animate({scrollTop: $('#header_lower').offset().top}, $speed);
$('#newsbox_content_wrapper').slideDown($speed);
$('.newsbox_toggle').removeClass('open');
//delay HTML replacement to sync with animation
$('.newsbox_expand').delay($speed).queue(function(n) {
$(this).html('Click to Close News Feature.');
$(this).addClass('rotate');
n();
});
} else {
//scroll back to top of body
$('html, body').animate({ scrollTop: 0 }, $speed);
$('#newsbox_content_wrapper').slideUp($speed);
$('.newsbox_toggle').addClass('open');
//delay HTML replacement to sync with animation
$('.newsbox_expand').delay($speed).queue(function(n) {
$(this).html('Click to Read More.');
$(this).removeClass('rotate');
n();
});
}
});
답변 해 주셔서 감사합니다. 내가 말했듯이, 나는 이것에 새로운 것이고, 체인은 내가 성취하고자하는 것에 가장 적합하다고 생각한다. 이걸 제대로 이해하면'.slideUp'이 완료된 후에'.html'이 실행됩니다. – mnelson7982
네, 맞습니다. '.slideUp'에 전달한 (익명) 함수는 애니메이션이 완료된 후에 실행됩니다. 거의 모든 jQuery 애니메이션 메소드는 콜백을 지원합니다. –
정말 고마워요. 당신은 매우 도움이되었습니다! – mnelson7982