问题
As a follow up from my previous question, I currently have this code on my live site:
http://jsfiddle.net/3veht/6/
It is the exact same thing as on the live site. But for some reason, when I go to open one of the drawers, it will work a single time (open and close) then if I try again, it will not work. No errors in console at all.
If I reload the page, it will work that single time again, then not open again.
To help, it is getting to the data sending part because it is returning data, it just won't slide down the drawer.
Maybe there is a better way to handle the slidedown for unique items? Here's a preview from the above fiddle:
$('.patient').click(function(){
var pat = $(this);
if ($('#drawer').is(':visible'))
$('#drawer').slideUp("slow", function () {
$('#drawer').slideDown('slow')
$('#drawer').load('/echo/js?js=' + pat.data('patientid'));
});
else
{
$('#drawer').slideDown('slow')
$('#drawer').load('/echo/js?js=' + pat.data('patientid'));
}
});
EDIT:
Drawer by default is set in css to display:none
I also notice when the drawer closes it sets a style to display:block to the drawer.
Maybe that helps..
Also, looking at the source, Jquery thinks it is showing the drawer. The animation is visibly moving in the source but nothing on the screen.
回答1:
Try this
$(".patient").click(function(){
var pat = $(this);
if ($("#drawer").is(":visible")) {
$("#drawer").slideUp("slow");
$("#drawer").load("/echo/js?js=" + pat.data("patientid"));
} else {
$('#drawer').slideDown("slow");
$('#drawer').attr("style", "display:block");
$("#drawer").load("/echo/js?js=" + pat.data("patientid"));
}
});
And working example http://jsfiddle.net/3veht/6/
来源:https://stackoverflow.com/questions/14472480/jquery-wont-slide-out-a-second-time