jquery - Having some trouble with .animate() -
i'm having trouble trying toggle multiple items.
here's summary of i'm trying achieve:
- there 5 divs (let's call them trigger-div) , there 5 other divs corresponds each trigger-div (let's call content-div)
- when click trigger-div1, it's corresponding content-div1 pop .animate()
- when click on trigger-div2, opened content-div1 close .animate() toggle width , after it's done closing, corresponding content-div2 open .animate().
- same goes other trigger-div. example, when click trigger-div3, content-div2 close , content-div3 open after.
here's code have far
<script> $(document).ready(function() { var div_id; var tile_object; var ele_about = 0; var ele_career = 0; var ele_restaurant = 0; var ele_contact = 0; var ele_blog = 0; var toggle_check = function (tile_object, div_id) { if (ele_about == 1){ animate_close("ele_about", tile_object, div_id, "#tile-blog"); } else if (ele_career==1){ animate_close("ele_career", tile_object, div_id, "#tile-career-content"); } else if (ele_restaurant==1){ animate_close("ele_restaurant", tile_object, div_id, "#tile-restaurant-content"); } else if (ele_contact==1){ animate_close("ele_contact", tile_object, div_id, "#tile-contact-content"); } else if (ele_blog==1){ animate_close("ele_blog", tile_object, div_id, "#tile-blog"); } else { animate_open(tile_object, div_id); } } var animate_close = function (tile_close, tile_open, div_id, div_close){ $(div_close).animate({ width: "toggle", }, 600, "linear", function (){ animate_open(tile_object, div_id); } ); tile_close = 0; } var animate_open = function (tile_object, div_id) { $(div_id).animate({ width: "toggle", }, 600); tile_object = 1; alert(ele_about) } $("#tile-about").click( function (){ toggle_check(ele_about, "#tile-blog"); }); $("#tile-career").click( function (){ toggle_check("ele_career", "#tile-career-content"); }); $("#tile-restaurant").click( function (){ toggle_check("ele_restaurant", "#tile-restaurant-content"); }); }); </script>
and here's html
<a id="trigger-about" href="#"><div id="tile-about" class="tile-about-inactive"></div></a> <div id="tile-career" class="tile-career-inactive"></div> <div id="tile-restaurant" class="tile-restaurant-inactive"></div><div id="tile-contact" class="tile-contact-inactive"></div> <div id="tile-blog" class="div-hide"> blog content </div> <div id="tile-about-content" class="div-hide"> career content </div> <div id="tile-career-content" class="div-hide"> career content </div> <div id="tile-restaurant-content" class="div-hide"> restaurant content </div> <div id="tile-contact-content" class="div-hide"> contact content </div>
"div-hide" class "display:none" css hide content , "tile--active" hover effect, works fine.
after running this, reason, "ele_" variable doesn't transition "toggle_check()" , "animate_open()" functions. noticed because alert(ele_about) keeps returning 0 value.
please help! i'm stumped :(
what need group trigger divs class, , content divs class, give them id. store id div should open data attribute of corresponding trigger div, when trigger div clicked can this:
$(".trigger-divs").click(function() { var contentdiv = $("div#"+$(this).attr('data')); $(".content-divs :visible").hide();//hide visible content div; contentdiv.slidedown();//fadein, animate({width: '600px'}) whatever want })
note: accessing data using attr, because hardcoded, , b because of differences in how jquery 1.4, , 1.6 encapsulate data stored using $.data method.
Comments
Post a Comment