Adding hover CSS attributes via jQuery/Javascript

后端 未结 4 613
离开以前
离开以前 2020-12-06 09:10

Some CSS styles need to be applied to an element on hover, and CSS styles have to be applied using javascript/jquery directly and not through stylesheets or $(this).ad

4条回答
  •  天涯浪人
    2020-12-06 09:41

    Try this:

    $('#some-content').hover(function(){
        $(this).css({ marginTop: '60px', display: 'inline-block' });
    }, function(){
        $(this).css({ //other stuff });
    });
    

    or using classes

    $('#some-content').hover(function(){
        $(this).toggleClass('newClass');
    });
    

    More info here .hover() and .toggleClass()

提交回复
热议问题