我有一个应用程序,可以在图像中放大 focus() 并放大 blur(). 。我已经阅读了原始图像大小,并在其上添加了15px,以创建生效的变焦,这很好。问题在于,我试图将我读到的原始图像大小传递给 .blur() 但是没有运气。有人可以帮助我解决这个问题吗?

有帮助吗?

解决方案

这是一个工作的演示 以下代码。

首先,您没有打电话 $.data() 方法开 orgWorgH 在你的 .blur() 功能。另外,我改变了你的 .blur() 功能与您的实现相似 .focus() 功能以使缩放工作进行工作:

$('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);
    });

});

其他提示

您也可以使用 '+=15''-=15' 在动画功能中。无需存储宽度和高度。

$('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);
});

演示

编辑:现在应该起作用。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top