javascript - 鼠标悬停时交换图像

标签 javascript jquery html css image

我在页面顶部有一张链接图片,下面有 5 张链接图片。当鼠标悬停在下面的图片上时,顶部图片应该更改为鼠标悬停的图像和鼠标悬停的链接,它的大小也应该是原来的两倍,但我什至无法更改图像/链接。

这是我的 jQuery 代码:

$(document).ready(function() {
$("google").mouseenter(function() {
        $("big").attr({
        "href": "http://i.imgur.com/oO1RrsF.png?1",
        "src": "http://www.google.com".
    });
});
$("apple").mouseenter(function() {
        $("big").attr({ 
        "href" : "http://www.apple.com",
        "src" : "http://i.imgur.com/eHm7Nbg.png?1"
    });
});

$("facebook").mouseenter(function() {
        $("big").attr({
        "href" : "http://www.facebook.com",
        "src" : "http://i.imgur.com/ovkudjR.png?2"
    });
});

$("hooli").mouseenter(function() {
        $("big").attr({
        "href" : "http://www.hooli.xyz",
        "src" : "http://i.imgur.com/yfEYkoZ.png?2"
    });
});

$("piedpiper").mouseenter(function() {
        $("big").attr({
        "href" : "http://www.piedpiper.com",
        "src" : "http://i.imgur.com/Q3IhTeK.jpg?1"
    });
});
});

big是顶部图像的 ID。我将 id 标签放在 <a href> 中包裹在 img 标签周围。我已经玩了一段时间了,但没有任何效果。任何帮助将不胜感激!

最佳答案

您的选择器是错误的。您想要以下任何一项。

$("#google"); //ID google
$(".google"); //Class google

对于所有其他选择器也是如此。

关于javascript - 鼠标悬停时交换图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30658569/

相关文章:

javascript - 在 Edge 浏览器中动态注入(inject) JavaScript 模块

javascript - 使用 d3 更新我的条形图时出错

javascript - 您可以更改 ui-grid 字体吗?

html - 无需悬停/鼠标悬停即可触发 CSS/HTML 图像摇动代码

javascript - 使用 NodeJS 向 JSON 文件键添加新属性

javascript - 光滑 slider : building a comparison slider

javascript - Jquery.html() 在 IE7 中不起作用,但 innerHTML 在同一个地方工作

javascript - 防止某些元素获得焦点

html - "infamous"CSS : 2 divs side-by-side, 跨浏览器版本(?)

javascript - 无法将我的纬度或经度附加到 html 文档?