나는 다음과 같은 코드를 사용하고 있습니다 :.top이 jquery TypeScript 정의 파일에 없습니다.
$('html, body').animate({ scrollTop: $($(this).attr('href')).offset().top });
타이프 라이터 나에게라는 오류 메시지주고있다 :
The property 'top' does not exist on value of type 'Object'
내가 추측하고 뭔가 jQuery를 정의 파일에서 누락되었습니다. 다른 사람들이이 문제를 보았거나 jQuery에서 일반적으로 사용하지 않는 무언가입니까? 그것은 내가 전에 보지 못한 것입니다.
자세한 내용은 jquery.d.ts 파일에서
$.fn.buildTableOfContent = function() {
"use strict";
var h2 = this.find('h2');
if (h2.length > 0) {
var h1 = this.find('h1:first');
if (h1.length === 0) {
h1 = this.prepend('<h1>Help</h1>').children(':first');
}
var menu = h1.wrap('<div class="h1 with-menu"></div>')
.after('<div class="menu"><img src="/Content/images/menu-open-arrow.png" width="16" height="16"><ul></ul></div>')
.next().children('ul');
h2.each(function (i) {
this.id = 'step' + i;
menu.append('<li class="icon_down"><a href="#step' + i + '">' + $(this).html() + '</a></li>');
});
menu.find('a').click(function (event) {
event.preventDefault();
$('html, body').animate({ scrollTop: $($(this).attr('href')).offset().top });
});
}
return this;
};
는 당신이'(오프셋 할 수 없습니다 시도 : {최고 : 번호; 왼쪽 : 숫자; };'TS 정의에서'? :'옵션 사용? –
@mcpDESIGNS 실제로 작동한다고 생각했지만 수정 된 선언이있는 편집 된 jquery.d.ts를 사용하고있었습니다. 어쨌든, 아니,'offset' 멤버를 선택적으로 만드는 것은 단지'JQuery' 인터페이스의 유효한 구현을 갖기 위해 구현 될 필요가 없다는 것을 의미합니다. 회원을 숨기기 위해 사용할 수있는 것으로 보이지 않습니다. jquery.d.ts 파일에 추가하려고하면 'offset'의 다른 오버로드가 유효하지 않게됩니다. 또한, 오프셋으로 선언해야합니까? :() => {위쪽 : 숫자; 왼쪽 : 숫자; };'구문 적으로도 유효해야합니다. – nxn