I have several DIVs on a page,only one is open and others are closed, I want that on click of a closed DIV it gets opened and, the previously opened DIV is closed, if any. It is all working fine, but the problem is: there is a lot of flicker seen in the scrollbar as well as the animating DIVs.
How can I remove this flicker ?
Please suggest ?
$(function () {
$(".OpenedIdea").find("img").first().click(CollapseFunction);
$(".ClosedIdea").find("img").first().click(ExpandFunction);
});
function CollapseFunction() {
$(this).attr("src", srcE);
$(this).unbind("click");
$(this).click(ExpandFunction);
$(this).parents("div.OpenedIdea").first().removeClass("OpenedIdea").
addClass("ClosedIdea");
var ideaDiv = $(this).parents("div").first().next();
ideaDiv.toggle("blind", 300, function () {
$("html,body").animate({ scrollTop: ideaDiv.offset().top - 100 },
{ duration: 'slow', easing: 'swing' });
});
}
function ExpandFunction() {
$(this).attr("src", srcC);
$(this).unbind("click");
$(this).click(CollapseFunction);
$(".OpenedIdea").find("img").first().click();
$(this).parents("div.ClosedIdea").first().removeClass("ClosedIdea").
addClass("OpenedIdea");
var ideaDiv = $(this).parents("div").first().next();
ideaDiv.toggle("blind", 300, function () {
$("html,body").animate({ scrollTop: ideaDiv.offset().top - 100 },
{ duration: 'slow', easing: 'swing' });
});
It’s a little hard to know without an example or your HTML, but it seems like what you want is the jQuery UI accordion. If you insist on doing it yourself, I would suggest something following this approach using a single click handler.
Then use a bit of CSS to handle the visual styling of the opener/closer