使用javascript制作精灵动画(每5秒一次)
我想使用js使我的动画每5秒运行一次 这是我的html代码使用javascript制作精灵动画(每5秒一次),javascript,jquery,html,css,Javascript,Jquery,Html,Css,我想使用js使我的动画每5秒运行一次 这是我的html代码 <div id="aa"></div> 这套衣服适合你吗 <div id="aa"></div> #aa { width: 167px; height: 169px; background-image: url("http://www.w3schools.com/cssref/pineapple.jpg"); animation: blinker 5s
<div id="aa"></div>
这套衣服适合你吗
<div id="aa"></div>
#aa {
width: 167px;
height: 169px;
background-image: url("http://www.w3schools.com/cssref/pineapple.jpg");
animation: blinker 5s forwards infinite;
}
@keyframes blinker {
50% {
opacity: 0.0;
}
}
它看起来像:
function animation()
{
$('#overlay').fadeIn('slow').delay(1000).fadeOut('slow');
}
setInterval(animation,5000);
我给你们做了一个示例,看看:你们可以在课堂上播放动画,然后每5秒钟添加和删除一个元素类
setInterval(函数(){
$(“div”).addClass(“play”);
setTimeout(函数(){
$(“div”).removeClass(“play”);
}, 1000);
}, 5000);代码>
div{
宽度:100px;
高度:100px;
背景:绿色;
}
.玩{
动画:播放1s;
}
@关键帧播放{
0%{左边距:0px;}
50%{左边距:200px;}
100%{左边距:0px;}
}
您想要使用css或javascript的解决方案吗?!我想你想要一个css解决方案,所以请更改标题我想要javascript中的代码你会在这里找到:Jquery FadeIn,FadeOut:你想用javascript更改图像的背景位置吗?你能把真实的链接设置到你的精灵图片上吗(上传到某个地方),这样我们就可以更清楚地了解你的意图。。。
var img = document.getElementById('aa');
var interval = window.setInterval(function() {
if (img.style.visibility == 'visible') {
img.style.visibility = 'hidden';
} else {
img.style.visibility = 'visible';
}
}, 1000);
function animation()
{
$('#overlay').fadeIn('slow').delay(1000).fadeOut('slow');
}
setInterval(animation,5000);