开发者

OnClick event not functioning to increase/decrease top margin

开发者 https://www.devze.com 2023-01-11 20:23 出处:网络
I have a DIV that im trying to adjust the top margin on upon click of the trigger link using jQuery. My code is below.

I have a DIV that im trying to adjust the top margin on upon click of the trigger link using jQuery. My code is below.

The problem is, this only works one way - decreasing the negat开发者_开发知识库ive top margin back down to 0. But on second click it doesnt increase it back up to -200px.

Anyone have any idea why?!

$('.gh-gallink').click(
    function() {
        $('.gallery_container').animate({ marginTop: "0px" }, 2000)
    },
    function() {
        $('.gallery_container').animate({ marginTop: "-200px" }, 2000);
    }
);


Instead of .click() you need .toggle() for it to cycle functions when clicked, like this:

$('.gh-gallink').toggle(
  function() {
    $('.gallery_container').animate({ marginTop: "0px" }, 2000)
  },
  function() {
    $('.gallery_container').animate({ marginTop: "-200px" }, 2000);
  }
);
0

精彩评论

暂无评论...
验证码 换一张
取 消