javascript - Div sliding from above the footer on click on another div -


i having trouble in sliding div bottom of page.

here jsfiddle

when click on blue box (arrow-hover) div slides up(box-main).

but hide div(box-main) again have click inside box-main div.

instead want hide div when again click on blue box(arrow-hover). tried lot,but unsuccessful.

and used position fixed both boxes when zoom in page box fixed , hides rest of page. if give position absolute or relative div(box-main) visible below footer, doesn't nice. there other way this.

here code

html:

 <div id="container"> <div id="box-main"></div> <div id="arrow-hover"></div>     <footer></footer> </div> 

css:

    #container {     margin:0;     width:100%;     height:100%; }  #box-main{     position: fixed;     left:150px;     bottom: -150px;     width: 250px;     height: 150px;     background: #000;     z-index: 100; } #arrow-hover{     position: fixed;     bottom: 50px;     left: 250px;     width: 50px;     height: 50px;     background: blue;     z-index: 100;  } footer {     width:100%;     background:green;     height:50px;     bottom:0;     left:0;     position:absolute;     z-index:500; } 

jquery:

 $('body').on('click','#arrow-hover',function(){     $('#arrow-hover').animate({         bottom: '200px'     },250);     $('#box-main').animate({         bottom: '50px'     },250); });    $('body').on('click','#box-main',function(){     $('#arrow-hover').animate({         bottom: '50px'     },250);     $('#box-main').animate({         bottom: '-150px'     },250); }); 

and want put upward arrow in (arrow-hover)div when clicked div moves , arrow should downwards, when again clicked div hides. there way of doing in jquery or javascript or css3.

any appreciated, lot.

since don't rely on variables, added class main box: "visible"

this class gets toggled in both animations, set, when show it, , removed, when hide it:

update: include arrows in clickable div, add "arrow up" class #arrow-hover element in html:

<div id="container">   <div id="box-main"></div>   <div id="arrow-hover" class"arrow-up"></div>   <footer></footer> </div> 

then add toggleclass function, arrow-hover click handler, switch between arrow-up , arrow-down class

$('body').on('click','#arrow-hover',function(){ if($('#box-main').hasclass("visible")) {     $('#arrow-hover').animate({         bottom: '50px'     },250).toggleclass("arrow-up arrow-down");     $('#box-main').animate({         bottom: '-150px'     },250).toggleclass("visible"); }else {      $('#arrow-hover').animate({         bottom: '200px'     },250).toggleclass("arrow-up arrow-down");     $('#box-main').animate({         bottom: '50px'     },250).toggleclass("visible"); } }); 

all have now, define arrow-up , arrow-down classes in css , set background image.

for purposes, use icon font "font awesome" http://jsfiddle.net/hapttwf6/28/ --> how looks ;)


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -

delphi - Indy UDP Read Contents of Adata -