您好想制作一个带有心跳效果的图像。 它必须调整一下,比如说最大20像素,然后再调整到原始大小。 它就像一个心跳,2个节拍 - 原创,2个节拍 - 原创。
到目前为止,我发现只有这种效果:
(function pulse(back) {
$('#seventyfive').animate(
{
'font-size': (back) ? '100px' : '140px',
opacity: (back) ? 1 : 0.5
}, 700, function(){pulse(!back)});
})(false);
或者你可以在这里查看:JSFiddle
答案 0 :(得分:11)
这样做
(function pulse(back) {
$('#seventyfive img').animate(
{
width: (back) ? $('#seventyfive img').width() + 20 : $('#seventyfive img').width() - 20
}, 700);
$('#seventyfive').animate(
{
'font-size': (back) ? '100px' : '140px',
opacity: (back) ? 1 : 0.5
}, 700, function(){pulse(!back)});
})(false);
答案 1 :(得分:5)
我会这样做,只需使用.animate
DEMO http://jsfiddle.net/kevinPHPkevin/D3X7R/72/
function pulse() {
$('#seventyfive').animate({
width: 300, height: 300, // sets the base height and width
opacity: 0.5
}, 700, function() {
$('#seventyfive').animate({
width: 320, height: 320, // sets the alternative height and width
opacity: 1
}, 700, function() {
pulse();
});
});
};
pulse();
答案 2 :(得分:5)
你不是真正的跳动心脏效果吗?
你还在等什么?检查以下内容;)
<强> HTML 强>
<img id="seventyfive"
src="http://upload7.ir/imgs/2014-02/60314995125165880641.png"/>
<强> CSS 强>
#seventyfive{
position:absolute;
font-size:100px;
top: 50px;
left: 50px;
font-weight:bold;
}
<强> JS 强>
var size = 150;
var s_size = 0.66 * size;
var m_size = 0.83 * size;
var s_resize = ( size - s_size )/2;
var m_resize = ( size - m_size )/2;
var image = $('#seventyfive').css('width',size);
var x = image.offset().left;
var y = image.offset().top;
function pulse() {
image.animate({
width: s_size, top:x+s_resize,left:y+s_resize
}, 350, function() {
image.animate({
width: size, top:x, left:y
}, 100, function() {
image.animate({
width: m_size, top:x+m_resize, left:y+m_resize
}, 70 ,function(){
image.animate({
width: size, top:x , left:y
}, 70, function() {
pulse();
});
});
});
});
};
pulse();
答案 3 :(得分:2)
<强> HTML 强>
<div><img id="seventyfive" src="http://winters.yorku.ca/wp-content/blogs.dir/271/files/2011/11/twitter-icon.png" /></div>
<强> JS 强>
(function pulse(back) {
$('#seventyfive').animate(
{
'font-size': (back) ? '100px' : '140px',
opacity: (back) ? 1 : 0.5,
height: (back) ? "100%" : "50%",
width: (back) ? "100%" : "50%",
'margin-top': (back) ? "0" : "25%",
'margin-left': (back) ? "0" : "25%"
}, 700, function(){pulse(!back)});
})(false);
<强> CSS 强>
#seventyfive{
position:absolute;
font-size:100px;
font-weight:bold;
}
答案 4 :(得分:2)
在CSS3中:
var timeoutThrottle,back = true;
$('#seventyfive').on('transitionend',function(e){
clearTimeout(timeoutThrottle);
timeoutThrottle = setTimeout(function(){ back = !back; pulse(back); },0);
});
var pulse = (function pulse(back) {
$('#seventyfive').toggleClass('heartBeat', back);
return pulse;
})(back);
答案 5 :(得分:0)
在此解决方案中,节拍数是参数(reps):
function pulse($cnt,time,reps){
reps = reps || 2;
(function beat(count) {
$cnt.animate({
opacity: (count<=0) ? 1 : 0.5
'font-size': (count<=0) ? '100px' : '140px',
}, time,
count==0? undefined :
function(){ beat(count<0? -count-1 : -count+1); });
})(reps+1);
}