SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Apr 2010
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    change div background image with link hover

    Ok, I need to accomplish the following...when I hover back and forth over a link in one area of a page, the background-image of a div in another part of the page needs to change back and forth. I have been trying all sorts of things in jquery with no results! Any ideas would be appreciated...here's the jquery script...


    Code:
    $function() {
    $("#about-lifebook").hover(over,out);
    	function over (event) {
         $(.spacer-bg-off).css("background", "url(images/spacer-content-bg.png)");
       }
       function out (event) {
         $(.spacer-bg-off).css("background", "none");
       });
    The link's id is "about-lifebook" and the div in question has a class of "spacer-bg-off". Any ideas? This ain't working at all.

    Edit: I just read this off of the jquery website: "The .hover() method binds handlers for both mouseenter and mouseleave events. We can use it to simply apply behavior to an element during the time the mouse is within the element."
    So perhaps the behavior has to be applied to the element being hovered over? How can I change the css of one element while hovering over another one?

  2. #2
    SitePoint Member
    Join Date
    Apr 2010
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Basically, I am trying to solve the issue shown in these pictures. When a nav item is hovered, the whole area below the nav needs to switch to the dark transparent bg shown in the image. The way I'm thinking of doing it is to create basically an empty div under the nav. It's not semantic but it needs to work in IE too, so after a lot of fiddling with pngs, I decided it was the most practical way. So, when the cursor is hovered over any nav item, the div would display the dark bg and when the cursor goes off a nav item, the div displays no background. Can anyone help me out here? How could this work?





Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •