Trying to disable a function that affects an element from its child element,

I am trying to create an accordion function similar to a blog, where you first see a set of lines (more precisely, 100px), and when you click on the blog title, the blog post expands to full height.

This is what I still have:

HTML:

                    <ul class="blog">

                        <li class="list-item">
                            <div class="list-item-left">
                                <h2 class="expand">Project Eden</h2>

                                <time>07.08.2012</time>
                            </div>
                            <div class="list-item-right">
                                <p>"Sed ut perspiciatis unde </p>                                   
                            </div>
                            <div class="list-item-whitespace"></div>
                        </li>

                        <li class="list-item">
                            <div class="list-item-left">
                                <h2>Project Eden</h2>

                                <time>07.08.2012</time>
                            </div>
                            <div class="list-item-right">
                                <p>"Sed ut perspiciatis unde</p>
                            </div>
                            <div class="list-item-whitespace"></div>
                        </li>

</ul>

jQuery:

var $listItems = $('.list-item');
var closedHeight = 100;
var slideSpeed = 1000;

$(".list-item").click(function() {
  if($(".list-item:animated").length) 
    return false;
}).toggle(function() { 
        var openHeight = $(this).parents("div:first").find(".list-item-right").height();
    $(this).animate({height:openHeight}, slideSpeed,"easeOutExpo");
    $(this).children('.list-item-whitespace').css({'display':'none'});
}, function(){
        $(this).animate({height:100}, slideSpeed,"easeOutExpo");
        $(this).children('.list-item-whitespace').css({'display':'block'});  
});

So basically what we are doing (as far as I understand, I am completely new when it comes to jQuery!):

We store some information in our variables and then define a function that will extend the .list-item to the actual height .list-item-right, and when we click it again, it will go back to its “closed” height of 100 pixels.

Now, what I want to do is not have a .toggle event or a .click event if you click .list-item.

, , .expand .list-item-left h2 ( ).

- , , , .

, K.

+3
1

. html. div. , , .

, , .

, , , div div overflow: auto, .

http://jsfiddle.net/WZVb6/1/

//set all blog posts to 100px to start
$('li.list-item h2').click(function() {
    $this = $(this);
    var nheight = $this.closest('.naturalheight').height();

    if ($this.hasClass('open')) {
        $this.closest('li').animate({
            height: 100
        });
        $this.removeClass('open');
    }
    else {
        $this.closest('li').animate({
            height: nheight
        });
        $this.addClass('open');
    }

});​
+1

All Articles