The data parameter is optional (note the very faint square brackets around
it on the doc page), so that isn't the problem.

The problem, as it is so often, is 'this':

var soffset = $(this).offset();

In the working code, 'this' is the #myinfo element.

In the broken code, 'this' is the #mycontent element.

There are several ways to solve that. Here is one solution, along with a bit
of code simplification:

var $myinfo = $("#myinfo");
$myinfo.mouseover(function(){
   $("#mycontent").load("mytext.txt",function(){
       var stop = $myinfo.offset().top;
       var ihgt = $("#footer").css("height");
       var $mydiv = $("#mydiv");
       var mhgt = $mydiv.outerHeight() + 50;
       var ntop = stop - mhgt;
       $mydiv.css("top",ntop).fadeIn("slow");
   });
});

-Mike

On Fri, Sep 18, 2009 at 5:37 AM, Dan G. Switzer, II <dswit...@pengoworks.com
> wrote:

> The second argument for the load() function is "data", not "callback":
> http://docs.jquery.com/Ajax/load#urldatacallback
>
> Do this instead:
>
>  $("span#mycontent").load("mytext.txt", {}, function(){
>    // callback code here
> });
>
> -Dan
>
> On Fri, Sep 18, 2009 at 5:51 AM, geegler <jkp_fb_st...@myvws.net> wrote:
>
>>
>> How come this code doesn't work?
>>
>> $("span#myinfo").mouseover(function(){
>>    $("span#mycontent").load("mytext.txt",function(){
>>        var soffset = $(this).offset();
>>        var stop = soffset.top;
>>        var ihgt = $("div#footer").css("height");
>>        var mtop = $("div#mydiv").css("top");
>>        var mhgt = $("div#mydiv").outerHeight() + 50;
>>        var ntop = stop - mhgt;
>>        $("div#mydiv").css("top",ntop);
>>        $("div#mydiv").fadeIn("slow");
>>    });
>> });
>>
>> This version works but, I don't want to display the div element until
>> the small text file has completed loading.
>>
>> $("span#myinfo").mouseover(function(){
>>    $("span#mycontent").load("mytext.txt");
>>    var soffset = $(this).offset();
>>    var stop = soffset.top;
>>    var ihgt = $("div#footer").css("height");
>>    var mtop = $("div#mydiv").css("top");
>>    var mhgt = $("div#mydiv").outerHeight() + 50;
>>    var ntop = stop - mhgt;
>>    $("div#mydiv").css("top",ntop);
>>    $("div#mydiv").fadeIn("slow");
>> });
>>
>
>

Reply via email to