jQuery: slideDown() causes flicker

In my example below, when you check the box to trigger slideDown() there is a quick flicker.

How can the flicker be avoided?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<title>Demo</title>

<style type="text/css">

div.xyz {
background: #eee;
padding: 10px;
margin: 10px;
}

div.xyz span {
display: none;
margin: 0;
padding: 0;
}

div.xyz span em {
margin: 0 0 0 20px;
display: block;
font-style: normal;
}

</style>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

</head>
<body>

<h1>Click Checkbox to Test Animation.</h1>

<div>
 <div class="xyz" >

  <p>
  <input class="selectMe" type="checkbox" value="1" />
  Click Here to Test
  <span>
   <em>
    Hello
   </em>
   <em>
    World
   </em>
   <em>
    <input type="text" />
   </em>
  </span>
  </p>

  <p>
  <input class="selectMe" type="checkbox" value="1" />
  Click Here to Test
  <span>
   <em>
    Hello
   </em>
   <em>
    World
   </em>
   <em>
    <input type="text" />
   </em>
  </span>
  </p>

 </div>
</div>

<script type="text/javascript">
/* <![CDATA[ */

	$('input:checkbox').attr('checked',false);
	$('.selectMe').click(function() {
	 if(  $(this).attr('checked')) $(this).siblings("span").slideDown(1000);
	 else $(this).siblings("span").slideUp();
	});

/* ]]> */
</script>

</body>
</html>

Open in new window

LVL 16
hankknightAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chuckaliciousCommented:
Which browser are you using? I've found that some of the animations are not very smooth in IE8. So much so that I've had to disable them and just use "show" and "hide".
0
darren-w-Commented:
I think its to do with the em's , look at animation jump here:

http://jqueryfordesigners.com/animation-jump-quick-tip/
0
hankknightAuthor Commented:
This is not caused by the <em>s and the problem is with all browsers.  If you test the code I posted you will see the problem.
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

darren-w-Commented:
ok,

here is a demo with and without the em styling:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>

        <title>Demo</title>

        <style type="text/css">

            div.xyz {
                background: #eee;
                padding: 10px;
                margin: 10px;
            }
            p.exp{
                margin: 0;
                padding:0;
                display: none;
            }

            div.xyz span {
                display: none;
                margin: 0;
                padding: 0;
            }

            div.xyz span em {
                margin: 0 0 0 20px;
                display: block;
                font-style: normal;
            }

        </style>

        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
        <script type="text/javascript">
            /* <![CDATA[ */
            $(function(){
                $('input:checkbox').removeAttr('checked');
                $('.selectMe').change(function(){
                    console.log('gothere')
                    $('p.exp').slideToggle('slow');
                    
                });
                $('.selectMe2').change(function(){
                    console.log('gothere')
                    $(this).siblings('span').slideToggle('slow');

                });
            })

            /* ]]> */
        </script>
    </head>
    <body>

        <h1>Click Checkbox to Test Animation.</h1>

        <div>
            <div class="xyz" >

                <p>
                    <input class="selectMe" type="checkbox"  />
                    Click Here to Test<br />
                </p>
                <p class="exp" >
                    Hello<br />
                    World<br />
                    <input type="text" />

                </p>

                <p>
                    <input class="selectMe2" type="checkbox" value="1" />
                    Click Here to Test
                    <span>
                        <em>
                            Hello
                        </em>
                        <em>
                            World
                        </em>
                        <em>
                            <input type="text" />
                        </em>
                    </span>
                </p>

            </div>
        </div>



    </body>
</html>

Open in new window


there is a little jump on the first item, though this is just down to styling
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hankknightAuthor Commented:
I still see a flicker.  There is a little jump on the first item.
0
hankknightAuthor Commented:
I see, there is no flicker in the first item where you removed the <em>s.  I was testing the second item. Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.