javascript - 使用jquery在鼠标悬停/悬停时放大图像

标签 javascript jquery html css

DEMO 这是我到目前为止的代码

我希望使用 jquery 在鼠标悬停或悬停时分别放大每个图像。我认为我有代码的主干,但它还没有完全工作。我是 jQuery 的新手,所以尝试理解一些在线文章一直是一个挑战,这是我在花了一个小时解决这个问题后所能看到的最接近的结果。

HTML

<img src="http://www.j-creative.biz/wp-content/uploads/2015/10/primary-colours-300x171.png" id="test" alt="" />
<br>
<img src="http://www.j-creative.biz/wp-content/uploads/2015/10/primary-colours-300x171.png" id="test1" alt="" />

jQuery

$('#test').hover(function() {
$(this).css({ width: "100%", height: "100%" });
 }, function () {
        $(this).css({ width: auto, height: auto });
});

最佳答案

请尝试一下

$(document).on({
    mouseenter: function () {
        $(this).css({ width: "100%", height: "100%" });
    },

    mouseleave: function () {
        $(this).css({ width: "auto", height: "auto" });
    }
}, '#test');

Fiddle Demo

您的答案缺失$(this).css({ width: "auto", height: "auto"});

$('#test').hover(function() {
$(this).css({ width: "100%", height: "100%" });
 }, function () {
        $(this).css({ width: "auto", height: "auto" });
});

Demo Your Answer

关于javascript - 使用jquery在鼠标悬停/悬停时放大图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35290408/

相关文章:

javascript - 如何使用普通 javascript 检查数据属性是否存在?

javascript - HTML onchange 不会从 Ajax 插入中触发

javascript - jQuery :not() Selector doesn't work

javascript - 删除 function.prototype 对象

javascript - Ecma6 promise : how to use Ecma6 promise to rewrite jquery $. 什么时候?

javascript - 如何在 jquery 中刷新 div onclick?

javascript - 将 Javascript Accordion 菜单效果与 jQuery 可过滤照片库相结合

javascript - 如何使用 jQuery 获取表单中的第一个唯一多值(数组标记)输入?

jquery - 如何捕捉 jQTouch 动画完成情况?

javascript - 我们如何为鼠标滚轮敏感的 <div> 制作样式滚动条