soniccool
soniccool

Reputation: 6058

Dropdown More errors

I have a script here that if i click on it drops down, as well on if i clickoutside it drops down. But i want to make it so that if i click on bottom it scrolls up. For some reason it doesnt work here. It only scrolls up if i click outside the box.

Heres an example. http://jsfiddle.net/w8mfx/

If i click on bottom it wont scroll up only if i click on outside. But i want it to work both ways.

$(document).ready(function() {
    $('#bottom').click(function(event) {
    event.stopPropagation();
    $('#content').slideDown();

});

    $('html').click(function(e) {
        //alert(1);
        if (e.target.id != 'bottom') {
            $('#content').slideUp();
        }
    });
});

Upvotes: 0

Views: 33

Answers (2)

Tyler Crompton
Tyler Crompton

Reputation: 12652

Use slideToggle(). http://jsfiddle.net/w8mfx/5/

Upvotes: 2

Jasper
Jasper

Reputation: 76003

http://jsfiddle.net/w8mfx/7/

I added:

$('#content').click(function (event) {
    event.stopPropagation();
});

so the user can click on the #content element and not trigger the slide function. That also means that the event handler for the html element can be simpler:

$('html').click(function(e) {
    $('#content').slideUp();
});

In the jsfiddle you may notice I cached the $('#content') selector in a variable since it was being used in more than one place.

Upvotes: 3

Related Questions