更改链接悬停时的背景图像

2022-01-22 00:00:00 hover jquery javascript css mouseover

所以我遇到了这个问题,即使我进行了彻底的网络搜索,我也找不到.

So I have this problem, which I couldn't find, even though I did a thorough websearch.

我正在制作我的作品集,背景是一个女人的照片,位于中间.在左侧,我有一个导航栏,其中包含指向其他页面的链接.

I am making my portfolio, and the background is a picture of a woman, located in the center. On the left I have a nav bar with link to other pages.

我基本上想要的是当我将鼠标悬停在其中一个链接上时要更改的背景图像.无论是通过CSS、Javascript还是JQuery,我都想知道是否可行.

What I basicly want, is the background image to change when I hover over one of the links. Whether it's through CSS, Javascript or JQuery, I want to know if it's possible.

提前谢谢你.

抱歉,我会尽力提供最好的.

Sorry, I'll try to provide the best I can.

<link rel="stylesheet" type="text/css" href="stylesheet.css">
<script src="jquery-1.10.2.min.js"></script>
<script src="jquery.js"></script>


<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>

<div class="header">/jacob gerlif pilegaard/</div>
<div class="underheader">portfolio</div>
<ul>
    <li><a href="index.html">Home</a></li>
    <li><a href="about.html">About</a></li>
    <li><a href="gallery.html"">Gallery</a></li>
    <li><a href="contact.html">Contact</a></li>
    </ul> 
 <h1>About me...</h1>
 <p> bla bla bla bla bla</p>
 <div id="circles"></div>

这是基本的html.id="baggrund" 是我想换成别的图片.

This is the basic html. The id="baggrund" is the image I want to change to something else.

#baggrund {
background-image: url(images/laerkeryg.jpg);
background-repeat: no-repeat;
width: 720px;
height: 394px;
position: absolute;
left: 805px;
top: 10%;}

这是我想要替换的图片的 CSS.

This is the CSS for the image I want to have replaced.

$( document ).ready(function() {
    $("#first").hover(function () {
    $("baggrund").css("background-image", 'url("images/Kat5.jpg")');
});
});

希望对您有所帮助,再次感谢.

Hope this helps, and thanks again.

推荐答案

这是一个通用的 jquery 答案:

Here's a generic jquery answer to your question:

$('a.class').on('mousein', function(){
   $('#portfolio').css('background-image', 'url("other.jpg")');
});
$('a.class').on('mouseout', function(){, function(){
  $('#portfolio').css('background-image', 'url("woman.jpg")');
});

相关文章