Jquery用心跳效果调整图像大小

Val*_*udu 10 javascript css jquery html5

您好想制作一个具有心跳效果的图像.它必须调整一下,比如说最大20像素,然后再调整到原始大小.这将像一个心跳,2节拍 - 原始,2节拍 - 原始.

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

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

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

Pat*_*ser 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);
Run Code Online (Sandbox Code Playgroud)


Kev*_*nch 5

我会像这样简单地使用它 .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();
Run Code Online (Sandbox Code Playgroud)


Kor*_*ndi 5

你不是一个真正的跳动心脏效果?
你还在等什么?检查以下内容;)

HTML

<img id="seventyfive" 
     src="http://upload7.ir/imgs/2014-02/60314995125165880641.png"/>
Run Code Online (Sandbox Code Playgroud)

CSS

#seventyfive{
    position:absolute;
    font-size:100px;
    top: 50px;
    left: 50px;
    font-weight:bold;
}
Run Code Online (Sandbox Code Playgroud)

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();
Run Code Online (Sandbox Code Playgroud)

小提琴演示在这里