我想知道javascript中的classname
與jQuery中的addClass
是否相同。 我想改變下列函數的jQuery:Classname javascript與addClass jQuery相同?
function slidePageFrom(page, from) {
// Position the page at the starting position of the animation
page.className = "page " + from;
// Position the new page and the current page at the ending position of their animation with a transition class indicating the duration of the animation
page.className ="page transition center";
currentPage.className = "page transition " + (from === "left" ? "right" : "left");
currentPage = page;
}
HTML:
<section id="homePage" class="page center" style="background-color: #add55a">
<h1>Home Page</h1>
<a href="javascript:slidePageFrom(page1, 'right');">Page 1</a>
</section>
<section id="p1" class="page right" style="background-color: #8ca83d">
<h1>Page 1</h1>
<a href="javascript:slidePageFrom(page2, 'right');">Back</a>
</section>
<section id="p2" class="page right" style="background-color: #8ca83d">
<h1>Page 2</h1>
<a href="javascript:slidePageFrom(homePage, 'left');">Back</a>
</section>
該函數中的第二條語句完全不符合第一條語句的作用。 – Pointy
jquery addClass將保留舊類並添加新類,您還可以使用removeClass刪除類 – brso05
@Pointy這就是它的意思;它是一個動畫(使用CSS轉換) – Tyblitz