Jquery call function on window resize and add attribute

212 Views Asked by At

I have a hover function on window load and some other conditions on window resize. I want to keep everything as is but I also want to call the thumbHover function on the window resize and add a css position attribute to info-top (only for the thumbHover function on the window resize), not for everything else. Can anyone help me? Many thanks!

function thumbHover() {
    $('.thumb').hover(function () {
            $('.info-top').text('Hover Text');
        },
        function () {
            if (!$('.info-top').hasClass('active')) {
                $('.info-top').text('');
            }
        });
}
thumbHover();
window.onresize = function () {
    if ($(".thumb").css("margin-bottom") === "1px") {
        $('.info-top').appendTo('#Grid');
    } else {
        $('.info-top').appendTo('#middle');
    }
};
1

There are 1 best solutions below

1
On
$(window).resize( function(){
  thumbHover();
  if ($("thumb").css("margin-bottom") === "1px") {
      $('.info-top').appendTo('#Grid');
      } else {
         $('.info-top').appendTo('#middle');
      }
  });

If you want to call the thumbHover(); then you have to put that function inside the resize function. and then add css with jquery after executing the thumbHover(); function