jQuery - Toggle Image Expand/Close

余生颓废 提交于 2019-12-24 18:25:15

问题


I have a dashboard pretty much a rip off of BBC.com which allows you to minimise and and expand the widget by clicking on a button.

When you've clicked on it, the image changes to indicate the widget is expanded or minimized.

Does anyone know how to do this in jQuery?


回答1:


Take a look here

Example:

$('.target').toggle();

If you want something to slide up and down you can try this:

   var visible = true;

    $("button").click(function () {
          $("p").slideToggle("slow", function () {
            visible = !visible;
            if (visible)
            {
              $('icon').attr('src', 'url_to_downimage.jpg');
            }
            else
            {
              $('icon').attr('src', 'url_to_expandimage.jpg');
            }
    });
  });


来源:https://stackoverflow.com/questions/6681638/jquery-toggle-image-expand-close

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