How to make this tab animation with jquery?

I would like this tab to live while hovering over

Before: before

On hover: after

How do I do this using jquery?

<div class="recruiterLink">
<a href="http://mydomain.com/recruiter/">
<span>Recruiting?</span>
<br>
Advertise a vacancy »
</a>
</div>

Thank!

+3
source share
3 answers

I would go as follows:

$(".recruiterLink").hover(function(){
 $(this).stop().animate({"top" : "-20px"});
}, function(){
 $(this).stop().animate({"top": "0"});
});

This means your div.recruiterLink must have positioning

.recruiterLink
{
    position: relative;
}
+3
source

this may be the start of what you are looking for:

$(document).ready(function() {

    $('#tab-to-animate').hover(function() {

        // this anonymous function is invoked when
        // the mouseover event of the tab is fired

        // you will need to adjust the second px value to
        // fit the dimensions of your image
        $(this).css('backgroundPosition', 'center 0px');

    }, function() {

        // this anonymous function is invoked when
        // the mouseout event of the tab is fired

        // you will need to adjust the second px value to
        // fit the dimensions of your image
        $(this).css('backgroundPosition', 'center -20px');

    });

});

Sorry, misrepresent the question this code should do, move the div as a whole, assuming you first clicked it using position: relative css property.

$(document).ready(function() {

    $('.recruiterLink').hover(function() {

        $(this).css({
            'position' : 'relative',
            'top' : 0
        });

    }, function() {

        $(this).css({
            'position' : 'relative',
            'top' : 20
        });

    });

});
+5
source

HTML

<div class="recruiterLink">
<a href="http://mydomain.com/recruiter/">
<span>Recruiting?</span>
<div class="hover-item" style="display:none;">Advertise a vacancy »</div>
</a>
</div>

JQuery

$(".recruiterLink").hover(function() {
  $(this).find(".hover-item").toggle();
}, 
function() {
  $(this).find(".hover-item").toggle();
});

, .

+1

Source: https://habr.com/ru/post/1776176/


All Articles