문제

I have an application which zooms in image on focus() and zooms out on blur(). I have read the original image size and added 15px to it in order to create the zoom in effect, which works fine. The problem is with the zoom out effect where I'm trying to pass the original image size that I have read to .blur() but with no luck. Could any one help me solve this issue?

도움이 되었습니까?

해결책

Here is a working demo of the following code.

First, you weren't calling the $.data() method on orgW and orgH in your .blur() function. Also, I've altered your .blur() function to have a similar implementation to your .focus() function in order to get the zoom out to work:

$('button:has(img)').blur(function() {

    if (timer !== null) clearTimeout(timer);

    var $image = $(this).find('img');

    $image.each(function() {
        $(this).animate({
            'width': $.data(this, 'orgW') + 'px',
            'height': $.data(this, 'orgH') + 'px',
        }, 500);
    });

});

다른 팁

You can also use '+=15' and '-=15' in the animation function. No need to store width and height.

$('button:has(img)').focus(function() {
    $(this).find('img').animate({
        width: '+=15',
        height: '+=15'
    }, 500);
});

$('button:has(img)').blur(function() {
    $(this).find('img').animate({
        'width': '-=15',
        'height': '-=15'
    }, 0);
});

Demo

EDIT: Now it should work.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top