JQuery Won't Slide Out a Second Time

走远了吗. 提交于 2019-12-25 03:57:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!