Javascript 轻弹IMG src属性以模拟闪烁
这里是新手!如果这很简单,我很抱歉 我有两张一个人的照片,睁着眼睛和闭着眼睛。闭上眼睛的文件末尾有一个“b”,因此: “/images/person.png”(睁大眼睛) “/images/personb.png”(闭上眼睛) 我想要的是非常快地将src切换到“mouseenter”,这样图像看起来像是在快速连续闪烁两次 我真的很感激任何帮助Javascript 轻弹IMG src属性以模拟闪烁,javascript,jquery,html,Javascript,Jquery,Html,这里是新手!如果这很简单,我很抱歉 我有两张一个人的照片,睁着眼睛和闭着眼睛。闭上眼睛的文件末尾有一个“b”,因此: “/images/person.png”(睁大眼睛) “/images/personb.png”(闭上眼睛) 我想要的是非常快地将src切换到“mouseenter”,这样图像看起来像是在快速连续闪烁两次 我真的很感激任何帮助 谢谢各位 以下是如何在HTML5中做到这一点: 只需将背景颜色替换为背景图像:url('your_url')在CSS中 HTML CSS 您可能需要使用
谢谢各位 以下是如何在HTML5中做到这一点: 只需将
背景颜色
替换为背景图像:url('your_url')代码>在CSS中
HTML
CSS
您可能需要使用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
});
你能发布相关的代码/标记吗。解决方案应该不会太难,但如果不看到您当前的设置/结构,几乎不可能提供任何内容。他希望图像在鼠标悬停时连续闪烁两次。
$('#your_flipping_img').bind('mouseover', function(){
$('#your_flipping_img').addClass('animate');
})
$('#your_flipping_img').bind('mouseout', function(){
$('#your_flipping_img').removeClass('animate');
})
#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;}
}
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
});