0

I'm trying (with very limited jQuery knowledge :) to animate a DIV when you hover over a thumbnail. I thought i could use the image ID in the REL to animate the DIV with that REL. For some reason all i end up is OBJECT OBJECT when i try to alert the div REL and it's kinda driving me nuts. Here's what i used:

    $(function(){

var screenCenter = $(window).width() / 2;
var projectID = this.id;

$(document).mousemove(function(e){
    if (e.pageX < screenCenter) {

    }
    else if (e.pageX > screenCenter) {

        $("#portfolio_thumbs img").hover(function() {

            //$("div[rel=" + projectID + "]").animate({left:'100px'},{queue:false,duration:300});

            alert($('div[rel=" + projectID + "]'))

        });


    }

    $('#portfolio_thumbs img').mouseout(function() {
        $(".project_description").animate({left:'-440px'},{queue:false,duration:300});
    });

});

What am i doing wrong?

vyegorov
  • 21,787
  • 7
  • 59
  • 73
Bart
  • 17
  • 4

2 Answers2

1

this.id is out of scope. You need to add it inside the hover callback:

$('#portfolio_thumbs img').hover(function() {
    $('div[rel="' + this.id + '"]').animate({left:'100px'},{queue:false,duration:300});
});

Simple concept demo: http://jsfiddle.net/f8tWY/

AlienWebguy
  • 76,997
  • 17
  • 122
  • 145
  • That worked! I´m more into designing so coding is not my thing, i was trying for a long time without succes. Thanks so much! – Bart May 05 '12 at 17:02
0

on your alert line, you have to check your quotes, because your variable is inside quotes there.

11684
  • 7,356
  • 12
  • 48
  • 71