作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 css 动画,可以在页面加载时在标题中滑动。如何做到单击链接时标题会滑出,而下一个标题会滑入? (使用 JavaScript)
这很可能非常简单,但我对此很陌生。
最佳答案
As you have not provided any code, i have no codebase to develop upon, so have created a sample demonstrating iterating titles. You can use your existing slide animation on top of this to get your desired output.
HTML
<div id="titleHolder"></div>
CSS
.title{
font-size:18px;
cursor:pointer
}
.hidden{
display:none;
}
JavaScript
const titles = ['StackOverflow', 'StackExchange', 'AskDifferent', 'Ask Ubuntu'];
const titlesLenght = titles.length;
const getTitleDomId = (title, index) => `${title}-${index}`;
const getTitleDom = (title, index) => `<span class="title ${index === 0 ? '' : 'hidden'}" id="${getTitleDomId(title, index)}" onclick="slideNext(${index}, ${index === titlesLenght -1 ? 0 : index+1});">${title}</span>`;
window.slideNext = (index, nextIndex) => {
document.getElementById(getTitleDomId(titles[index], index)).style.display = 'none';
document.getElementById(getTitleDomId(titles[nextIndex], nextIndex)).style.display = 'block';
};
for (let i = 0; i < titlesLenght; i++) {
document.getElementById('titleHolder').innerHTML += getTitleDom(titles[i], i);
}
链接到jsFiddle
Make sure you supply your code with question for faster and more relevant answers.
关于javascript - 如何用Javascript引用CSS动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43037772/
我是一名优秀的程序员,十分优秀!