简体   繁体   English

通过将鼠标悬停在页面上来更改页面的背景图像

[英]Changing background image of page by hovering over buttons

This is what I got so far: fiddle . 这就是我到目前为止得到的: 小提琴 I've got a background that I want to change to a different image when I hover over a button (and there will be several buttons, several images). 我有一个背景,当我将鼠标悬停在一个按钮上时,我想将其更改为其他图像(会有多个按钮,多个图像)。

$(document).ready(function(){ 
    $("#leo_land3_div").hover(function() {
        $("#fish").stop().fadeOut("fast", function() {
            $("#fish").css("background-image", "url('http://i.imgur.com/a0HBqz3.jpg')").fadeIn(700);
        });
    }, function() {
        $("#fish").stop().fadeOut("fast", function() {
            $("#fish").css("background-image", "url('http://i.imgur.com/lJ7Zmi7.jpg')").fadeIn(700);
        });
    });
    });

$(document).ready(function(){ 
    $("#leo_land3_div2").hover(function() {
        $("#fish").stop().fadeOut("fast", function() {
            $("#fish").css("background-image", "url('http://i.imgur.com/ThRxyIM.jpg')").fadeIn(700);
        });
    }, function() {
        $("#fish").stop().fadeOut("fast", function() {
            $("#fish").css("background-image", "url('http://i.imgur.com/lJ7Zmi7.jpg')").fadeIn(700);
        });
    });
    });

HTML: HTML:

HTML:

<div id="fish">
<div id="leo_land3_div"><a href="#">TTT</a> </div>
<div id="leo_land3_div2"><a href="#">TTT 3</a> </div>    
</div>

CSS: CSS:

#fish{background-image:url("http://i.imgur.com/lJ7Zmi7.jpg");width:459px;height:474px;}

I'm almost there! 我快到了! It works perfectly with a single button. 一个按钮即可完美工作。 Not so much with two. 没有两个。 The main issue I can't fix is getting the background images to fade to each other, not to "nothing" and then back. 我无法解决的主要问题是使背景图像彼此渐隐,而不是“无”然后返回。 Also not sure what is happening when I add another link. 也不确定当我添加另一个链接时发生了什么。

These guys have done exactly what I want, but I don't have the mettle to figure out HOW they did it. 这些家伙确实做了我想要的,但是我没有勇气想出他们是如何做到的。

Change your fades to animate and set queue to false so they run in parallel: 将渐变更改为animate ,并将queue设置为false,以便它们并行运行:

.animate(
    { opacity: 0 },
    { queue: false, duration: 'slow' }
  )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM