Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Animate with Jquery through id

I am very new to Jquery. This is also my first time asking a question on here. I am trying to animate this id but I do not know how to apply it with an id. I want my name to move to the left, enlarge, and lessen the opacity right when the code runs, without a button.

$(document).ready(function(){
  $(name).animate({
    left: '250px',
    opacity: '0.5',
    height: '150px',
    width: '150px'
  });
}); 
#name{
    font-size:40px;
    font-weight: 700;
    font-family: Roboto;
}
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" type="text/css" href="style.css">
        <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
        <link rel='stylesheet' href='https://fonts.googleapis.com/css?family=Roboto'>
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
        <script src="resume-animations.js"></script>
    </head>
    <body>
        <div id="name">Christy Kim</div>
    </body>
</html>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Firstly, selectors in jQuery follow CSS rules. Therefore to select the <div id="name"> element you should use $('#name') instead of $(name).

To actually have the element move position it needs to be set to position: absolute in CSS.

With those updates made, your code works fine:

$(document).ready(function() {
  $('#name').animate({
    left: '250px',
    opacity: 0.5,
    height: '150px',
    width: '150px'
  });
});
#name {
  font-size: 40px;
  font-weight: 700;
  font-family: Roboto;
  position: absolute;
}
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

<div id="name">Christy Kim</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading