Im having a problem, I have managed to get some code to make a div element slide up into view but how would I get it to slide down again if the close button has been clicked? so that I can keep pressing the link and it will play the animation again rather then just showing the div already in its final position.
heres the jquery code
$(document).ready(function() {
//select all the a tag with name equal to modal
$('a[name=modal]').click(function(e) {
//Cancel the link behavior
e.preventDefault();
//Get the A tag
var id = $(this).attr('href');
//Get the screen height and width
var maskHeight = $(document).height();
var maskWidth = $(window).width();
//Set height and width to mask to fill up the whole screen
$('#mask').css({'width':maskWidth,'height':maskHeight});
//transition effect
$('#mask').fadeIn(600);
//Get the window height and width
var winH = $(window).height();
var winW = $(window).width();
//Set the popup window to center
$(id).css('top', winH/2-$(id).height()/2);
$(id).css('left', winW/2-$(id).width()/2);
//Slide up Boxes Div transition effect
$(id).css({display:'block'}).animate({marginTop:'0px', opacity:'1', },400);
});
//if close button is clicked
$('.window .close').click(function (e) {
//Cancel the link behavior
e.preventDefault();
$('#mask, .window').hide();
});
//if mask is clicked
$('#mask').click(function () {
$(this).hide();
$('.window').hide();
});
});
thanks
You can just do the opposite of what you are doing to slide-up the element:
There are a few errors in your code:
.animate({marginTop:'0px', opacity:'1', },400)has a trailing comma that will force errors in Internet Explorer, it should be:.animate({marginTop:'0px', opacity:'1' },400)..csstwice in a row on the same element, you can just pass an object to the.cssfunction like you do further down in your code:.
Notice I also chained the
.animate()function call, this way you only select$(id)once..slideUp() and .slideDown()
Are you aware that jQuery already has functions that do this?
.slideUp(): http://api.jquery.com/slideup.slidedown(): http://api.jquery.com/slidedown.slideToggle(): http://api.jquery.com/slidetoggleUPDATE
Here is an updated version of your jsfiddle: http://jsfiddle.net/4hw8H/1/