10

你好想制作一个带有心跳效果的图像。它必须调整一下大小,比如说最大 20 像素,然后变成原始大小。就像心跳一样,2 拍 - 原始,2 拍 - 原始。

到目前为止,我只发现了这种效果:

    (function pulse(back) {
    $('#seventyfive').animate(
        {
            'font-size': (back) ? '100px' : '140px',
            opacity: (back) ? 1 : 0.5
        }, 700, function(){pulse(!back)});
})(false);

或者你可以在这里查看:JSFiddle

4

6 回答 6

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);
于 2013-09-13T08:35:14.533 回答
6

我会这样做,只需使用.animate

演示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();
于 2013-09-13T08:39:13.357 回答
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();

小提琴演示在这里

于 2014-02-13T21:31:23.887 回答
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;
}

小提琴演示在这里

于 2013-09-13T08:41:27.420 回答
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);
于 2013-09-13T08:51:50.837 回答
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);
 }
于 2014-11-12T18:34:37.427 回答