わかりましたので、既存のコードを少しリファクタリングしました。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 + "%";
}
};
自分で試してみてください