轻击IMG src属性以模拟眨眼
Flick IMG src attribute to simulate blinking
新手来了!如果这太简单了,我很抱歉。
我有一个人的两幅图像,睁开眼睛和闭上眼睛。eyes closed文件的末尾有一个'b',所以:
'/images/person.png' (eyes open)'/images/person .png'(闭上眼睛)
我想要的是在'mouseenter'上快速切换src,这样图像看起来就像快速连续闪烁两次。
我很感激你的帮助。
谢谢伙计们!
如何在HTML5中做到这一点:
JSFiddle的实例
在你的CSS中将background-color
替换为background-image:url('your_url');
。
HTML
<div id="your_flipping_img"></div>
JS
$('#your_flipping_img').bind('mouseover', function(){
$('#your_flipping_img').addClass('animate');
})
$('#your_flipping_img').bind('mouseout', function(){
$('#your_flipping_img').removeClass('animate');
})
CSS #your_flipping_img{
background-color:#efefef;
width:150px;
height:150px;
}
.animate{
-webkit-animation: flicking .5s; /* Chrome, Safari, Opera */
animation: flicking .5s;
}
@-webkit-keyframes flicking {
0% {background-color: red;}
25% {background-color: #efefef;}
50% {background-color: red;}
100% {background-color: #efefef;}
}
/* Standard syntax */
@keyframes flicking {
0% {background-color: red;}
25% {background-color: #efefef;}
50% {background-color: red;}
100% {background-color: #efefef;}
}
你可能需要用javascript来做。
假设您的图像是#blinkingimage
:
function blinkImage(image,num) {
setTimeout(function() {
image.src = 'images/personb.png';
setTimeout(function() {
image.src = 'images/person.png';
}, 50); // Set this to however long you want the blink to be, in milliseconds
}, 50); // Set this to however long you want the delay to be, in milliseconds
}
$('#blinkingimage').hover(function() {
blinkImage($(this),1); //You said you want it to blink twice, so you'll need to call blinkImage twice
setTimeout(function() {
blinkImage($(this),2);
}, 100); // Set this to twice the length of one blink call
});
相关文章:
- 在VanillaJS中模拟模型双向数据绑定
- RegEx删除空属性?例如,如果(class=“”||class=“”)移除;否则就下课
- 全局变量和全局对象的属性之间有什么区别吗
- 如果使用 lodash 将属性存在于另一个对象中,则向对象添加属性
- 如何在Bootstrap Modal中为动态点击生成的变量设置jade属性
- 如何模拟JavaScript对象或数组中缺少的属性或元素
- Javascript模拟“悬停”触发CSS属性
- 模拟“类”时,为什么要在 .prototype 属性中设置方法,而不是在构造函数本身中设置方法
- 如何模拟余烬的 IoC 注入的属性
- 如何模拟链接的下载属性
- 模拟服务返回promise:无法读取未定义的属性
- 无法读取属性'spyOn'of null-模拟angularJS单元测试中的承诺
- 是否可以模拟不可枚举的属性
- 轻击IMG src属性以模拟眨眼
- 用Jasmine有效地模拟全局属性
- 在Scala Lift中模拟Html5占位符属性
- JS -模拟表单提交"表单属性"关于文本输入
- 适当模拟“模式”属性
- 如何在JavaScript中模拟带有参数的属性
- 如何在karma/mocha测试套件中模拟窗口对象属性