해당 항목을 클릭하면 내용을 숨기고 표시하는 테이블 세트가 있습니다. 또한 scrollTop을 사용하여 클릭 된 각 테이블의 맨 위에 표시하여 내용을 더 잘 보여줍니다. 지금까지 아무런 문제가 없습니다 ... 기본적으로 첫 번째 표의 내용을 표시하고 싶지만이 경우 페이지가로드 될 때 scrollTop을 방지하고 싶습니다. 내가 어떻게 해?jQuery : 시뮬레이션 클릭() 또는 트리거 ('클릭')시 스크롤 탑 방지
$(document).ready(function() {
$('table tr').nextAll().hide();
var $button = $('table th').css('cursor', 'pointer');
$button.click(function() {
$(this).parent().nextUntil('table th').toggle();
$('html, body').animate({
scrollTop: $(this).offset().top
}, 500);
});
$('table th:eq(0)').trigger('click', animate(false));
});
.trigger()에는이 첫 번째 스크롤을 방지하는 데 도움이되는 코드가 있어야합니까? 도움 주셔서 감사합니다.
는 편집 :
$(document).ready(function() {
$('table tr').nextAll().hide();
var $button = $('table th').css('cursor', 'pointer');
$button.click(function() {
$(this).parent().nextUntil('table th').toggle();
});
$('table th:eq(0)').trigger('click');
$button.click(function() {
$('html, body').animate({
scrollTop: $(this).offset().top
}, 500);
});
});
이 코드의 예이다 : http://luxurycruisesgalapagos.com/test.html –