Author Topic: CSS WTF  (Read 1781 times)

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14310
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
CSS WTF
« on: April 13, 2012, 11:56:06 AM »
I have a div that I'm trying to position and show (it's a hover menu) and I'm using JQuery to do it.  The thing is, I can watch it make the changes using Firebug and it changes the display of the item and it goes to display:block but it still shows as hidden in Firebug and it's obviously not appearing on the page.  Any ideas???

Code: [Select]
        var $more1 = $("#more1"), pos, width;

       
        function showMoreMenu(menu, id) {
            pos   = $("#"+id).offset();
            width = $("#"+id).width();
            height = $("#"+id).height();
            menu.css({ "left": (pos.left - 5) + "px", "top":(pos.top + height) + "px" }).prependTo("#"+id).show();           
        }
       
        function hideMoreMenu(menu) {
            menu.hide();
        }
       
        $("#arrow1").mouseover(function() { showMoreMenu($more1, "arrow1"); });
        $("#arrow1").mouseout(function() { hideMoreMenu($more1); });

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14310
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: CSS WTF
« Reply #1 on: April 13, 2012, 11:58:54 AM »
The even more strange thing is... if I comment out everything in showMoreMenu and change it to:

menu.show();

It works.  So it's like it doesn't like the chaining or something.

micah

  • A real person, on the Internet.
  • Ass Wipe
  • Posts: 6915
  • Karma: +58/-55
  • Truth cannot contradict truth.
    • micahj.com
Re: CSS WTF
« Reply #2 on: April 13, 2012, 12:02:38 PM »
is it because you're prepending the menu TO arrow1 instead of arrow1 TO the menu?

what if you just change "prependTo" to plain old  "prepend"
"I possess a device, in my pocket, that is capable of accessing the entirety of information known to man.  I use it to look at pictures of cats and get in arguments with strangers."

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14310
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: CSS WTF
« Reply #3 on: April 13, 2012, 12:08:12 PM »
Ok, got it sorted.  Apparently you must prependTo the contents of an element.  I was trying to prepend the menu to an img tag and you need to prepend to the contents of a div or a span or something.  I change it to a span and now it's working.  It's not putting it in the right position, but whatever.

Mike

  • Jackass In Charge
  • Posts: 11257
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Re: CSS WTF
« Reply #4 on: April 13, 2012, 12:09:38 PM »
the prependTo looks right.  He wants attach the menu to the element that caused the hover.

I would probably change the order of the chaining though.  Try show().prependTo()

BTW there is a offset() function you can use instead of building the css part
Code: [Select]
menu.offset({left: pos.left - 5, top: pos.top + height})

edit: Ah, you posted in the meantime.  Yeah, prepending to an img tag doesn't work too well :P