이 좋아, 그래서 기존의 코드를 가져다가 그것을 조금 리팩토링 : 이런 경우,이 시도. jQuery 호출은 이와 같이 간단합니다.
$("#opener").click(function() {
myApp.websiteOpener.displayWebsite('hider1', 'hider2');
});
그런 다음 필요한 코드가 들어있는 별도의 파일이 있습니다.
var myApp = {};
myApp.websiteOpener = {
up: null,
down: null,
topPanel: null,
bottomPanel: null,
displayWebsite: function(tPanel, bPanel) {
if (typeof up !== "undefined") return;
topPanel = tPanel;
bottomPanel = bPanel;
up = setInterval(this.goUp, 2);
down = setInterval(this.goDown, 2);
},
goUp: function(x) {
var h1 = document.getElementById(this.topPanel);
if (h1.offsetHeight <= 0) {
clearInterval(up);
return;
}
h1.style.height = parseInt(h1.style.height) - 1 + "%";
},
goDown: function(x) {
var h2 = document.getElementById(this.bottomPanel);
if (h2.offsetHeight <= 0) {
clearInterval(down);
return;
}
h2.style.top = parseInt(h2.style.top) + 1 + "%";
h2.style.height = parseInt(h2.style.height) - 1 + "%";
}
};
Try it for yourself
왜 jQuery를 필요하지 않는 무언가에 부풀게 추가? –
js에서 이미 작업하고 있다면 jQuery에서 왜 그것을하고 싶습니까? – lbstr
글쎄, 만약 코드가 단순화 될 수 있다면 조금 더 부드럽게 움직일 것이라고 생각했다. 죄송합니다. 원본 게시물을 업데이트했습니다. 빠른 답변을 주셔서 감사합니다. – itsbc