Jump to content

Recommended Posts

Hi
 
I am creating a site using bootstrap and have a few collapsed panels, the trouble I am having is when the page first loads the down arrow needs pressing twice before it does anything, can this be fixed 
 
 
js

$(document).on('click', '.panel-heading span.clickable', function(e){
    var $this = $(this);
	if(!$this.hasClass('panel-collapsed')) {
		$this.parents('.panel').find('.panel-body').slideUp();
		$this.addClass('panel-collapsed');
		$this.find('i').removeClass('fa fa-arrow-up').addClass('fa fa-arrow-down');
	} else {
		$this.parents('.panel').find('.panel-body').slideDown();
		$this.removeClass('panel-collapsed');
		$this.find('i').removeClass('fa fa-arrow-down').addClass('fa fa-arrow-up');
	}
})

And this is the code for the header

<div class="panel-heading">
     <span class="pull-right clickable"><i class="fa fa-arrow-down" aria-hidden="true"></i></span>
     <h4><i class="fa fa-calendar" aria-hidden="true"></i> Important Events </h4>
     </div>

Thanks for any help in advance

Link to comment
https://forums.phpfreaks.com/topic/303174-collapsed-button-needs-pressing-twice/
Share on other sites

I think you're confusing what is clickable and what is not:

https://jsfiddle.net/Strider64/db8NB/

 

While that isn't the same thing it should show you what I'm talking about.

$(function () {

    var myButton1 = $('.myButton1'), // The Button:
        box1 = $('.box1'),
        myButton2 = $('.myButton2'),
        box2 = $('.box2');

    myButton1.on('click', function () {

        $(this).toggleClass('off');
        if ($(this).hasClass('off')) {
            moveRight(); // Animate Box to the Right:
        } else {
            moveLeft(); // Move Box back to the Original Position:
        }
    });

    myButton2.hover(function () {
        box2.animate({
            'left': '300px'
        });
        $(this).css('background-color', 'orange');
    }, function () {
        box2.animate({
            'left': 0
        });
    });

    function moveLeft() {
        box1.animate({
            'left': 0
        });
    }


    function moveRight() {
        box1.animate({
            'left': '300px'
        });
    }
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.