4

I asked this question and the answer works really well.

The only thing though is that now I need a version that scrolls directly to the respective div instead of scrolling through all of them (i.e. if you hover over the last link, it won't scroll through 6 former divs to get to it).

It still needs to return to the first div when you aren't hovering over the link.

Also, it would be most ideal if there was also a way to stay on that div if you hover over it as well as its link. As of now, the div is not intractable because when you hover over it and leave its link, it scrolls away.

Thanks.

Community
  • 1
  • 1
scferg5
  • 2,003
  • 5
  • 22
  • 28

4 Answers4

3

Try that way:

DEMO fiddle

var flag = false,
    goto = 0,
    hre;

    $('#nav li a').bind('mouseenter mouseleave', function(e) {
        if (e.type === 'mouseenter') {
           flag = true;
           hre = $(this).attr('href');
           goto = $(hre).position().top;
           $('#sections').stop().animate({top : '-'+goto },800);  
        } else {
           flag = false;

            setTimeout(function() {
               if( flag != true ){
                  $('#sections').stop().animate({top : '0' },800);  
               }      
            }, 1000);  
        }
    });

$('#sections').mouseenter(function(){
   flag = true;
});

After you hover an anchor, go fast into the 'wrapper' and it won't go back to the 1st slide.


BTW... why you just don't create something more... practique? :)

EXAMPLE fiddle

Roko C. Buljan
  • 196,159
  • 39
  • 305
  • 313
1

I'm pretty sure what you are asking is impossible for this reason:

First you want to have the animation return the top when the user is not hovering over the link BUT you also want to be able to stay on the div when the user LEAVES the link and hovers over the div it scrolled to.

Here is a jsfiddle which does the first part of your question though.

http://jsfiddle.net/YWnzc/8/

I just set the animation time to 0

Keith.Abramo
  • 6,952
  • 2
  • 32
  • 46
  • I guess what functionality we're looking for is something similar to the standard unordered lists with sub-lists to create dropdown menus. The submenu gets accessed by hovering over the parent
  • , but also stays open when hovering over the submenu itself. I apologize for unclear wording.
  • – scferg5 Nov 22 '11 at 19:12
  • Those are structured in such a way where the header AND the sub menu are contained in the same wrapper element and there is usually a hover effect which just changes the height of that wrapper element to expose the previously hidden sub menu. This is not possible given your current markup – Keith.Abramo Nov 22 '11 at 19:14
  • If you want something like that user984008 then here's a fiddle demo of something similar I did earlier today for another question: http://jsfiddle.net/Wxpxq/ – Jeff Wilbert Nov 22 '11 at 19:15