Guide to effectively integrating jQuery's .animate() function utilizing an external JavaScript file?

I am currently in the process of building my professional portfolio to prepare for upcoming job opportunities. As someone who is new to the concepts I am practicing, I have encountered a challenge while trying to use jQuery's .animate() method. While I can easily utilize jQuery's .css() method, I face issues when attempting to implement .animate(); nothing seems to happen.

Despite rearranging the CDNs and Script tags within my Bootstrap and Semantic setup along with my custom CSS and JavaScript files, the problem persists.

Current order:
In the head:
Bootstrap CSS CDN
Bootstrap js CDN
Semantic CSS CDN
Custom Relative CSS

Before closing body tag:
jQuery js CDN
Popper js CDN
Semantic js CDN
Custom Relative JS (contains problematic code)

<button class="ui green basic button" id="click">Click</button>
<div id="trans">
    <h4>Hello World</h4>
</div>
$('#click').click(function(){
    $('#trans').animate({
        width: "50%"
    }, 500, function(){
        alert("animated");
    });
});
This Does Nothing
$('#click').click(function(){
    $('#trans').css({
        width: "50%"
    });
});
This Works As Intended

Upon clicking the button with the ID of "click," I would expect the div with the ID of "trans" to decrease its width from 100% to 50% and display an alert saying "animated." However, this action does not occur at all. What puzzles me most is that using the .css() method to change the same property works without any issues, albeit lacking the desired animation effect.

Answer №1

Could it be possible that you're simply overlooking it? https://jsfiddle.net/b4EZJy9u/2/

I made sure to apply some initial CSS to the #trans DIV

#trans {
  background: blue;
  display: inline-block;
  width: 50%;
}

Answer №2

In HTML:

<button class="ui green basic button" id="click">Click</button>
    <div id="trans" style="background-color: #f00;">
        <h4>Hello World</h4>
    </div>

In JavaScript

$('#click').click(function(){
          $('#trans').animate({
              width: "50%"
          },500,function(){
            alert("animated");
          });
      });

Everything seems to be in order. Take a look at this: codepen.io

If anything appears out of place, it could be due to modifications made in CDN files.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The text box is intersecting with the photo

Struggling to craft a clean layout with an upvote button, I encountered an issue where the textarea appears to overlap with the image. Below is my sample code snippet: .my-component-row { display: flex; justify-content: center; align-items: center ...

Text situated under a stylish Css bar

I want to create a bar chart to display the number of surveys that are completed, not started, and not available. The bars should also show the actual numbers below them, similar to this example https://i.sstatic.net/8miIs.png Currently, I have the fol ...

Loop through an array of values in AngularJS

Here is an example of an array: [ {type:'x', value:'123'}, {type:'y', value:'456'}, {type:'z', value:'789'}, {type:'w', value:'012'}, {type:'q&apo ...

Issue with data transfer in Angular 6 routes

I created an application that showcases a table of different cars: Here is my code snippet for the car component: Carcomponent.html <tbody> <tr *ngFor="let car of allCars; index as carId" \> <td [routerLink]="[&apos ...

Troubles encountered when attempting to send 'Post' and 'GET' requests from PhoneGap app on iOS to PHP server

In my PhoneGap app on iOS, I am attempting to make a jQuery Post call to a PHP file located on a server. The command in question is: $.post({url:'http://example.com/uploadtest/addContent.php', data: JSONstring, success:contentSent}); I have set ...

Encountered a Three.js error labeled as Uncaught TypeError while trying to follow

I've been following a tutorial on how to integrate three.js into my project from this video: https://www.youtube.com/watch?v=1TeMXIWRrqE I copied the source code provided at the bottom of this webpage: After downloading and extracting the model into ...

Adjust the iFrame's CSS width to 100% to mimic the scale of an image

I am attempting to apply CSS to scale an iFrame by setting width: 100%, while also having the height adjust proportionally to the width. This resizing technique works perfectly with an <img> tag. Both the image and the iFrame have their width and h ...

The AJAX request made right before submitting the form is not functioning

I have a Spring MVC - JSP web application in which I need to populate a text value input with JS/jQuery before submitting a form. The information for this input comes from an AJAX call that should be triggered when the submit button is clicked, but before ...

After jQuery, let's dive into the world of

Imagine if my HTML input looked something like this: <input type="text" class="hello"> I attempted to use jQuery alongside ajax to add an element after it, as shown below: $(".hello").after("<p>"+response."</p>"); //response contains d ...

What is the best way to implement absolute positioning on a flex element?

My component, called AppBar.vue, is structured like this: <template> <v-row> <v-spacer></v-spacer> <v-btn text="Our plans"></v-btn> </v-row> </template> When I use it as intended, it lo ...

Struggling to find and interact with a button element, however Selenium Webdriver is throwing a NoSuchElementException

After experimenting with various selectors and attributes in an attempt to target and click a sign-up button on a website's homepage, I have been unsuccessful. The website in question can be found at: When the webdriver is initiated, all actions are ...

List-group item in Bootstrap 4 featuring an arrow on the right side

Currently, I am utilizing Bootstrap 4 and are in need of developing a list-group featuring a title as well as an arrow positioned on the right side. This is what I currently have: <div class="accordion" id="accordionExample"> & ...

What steps can be taken to transform example.com/blog.html into example.com/blog?

www.awesomenewgames.com/articles I need to change the URL of this page from ending with /articles to simply /blog. So the desired result should be: www.awesomenewgames.com/blog What steps do I need to take to make this change? Any guidance on this matte ...

Bootstrap allows for placing three radio buttons in each row within an ASP radio button list

Is it possible to display three radio buttons from the asp:RadioButtonList rblbase in one row, similar to the code below? <div class="row"> <div class="col-sm-4"> Radio1 </div> <div class="col-sm-4"> Radio2 </div> &l ...

Containers do not line up properly with each other. Adjusting the width leads to unexpected consequences

As someone who is new to HTML and CSS, I am facing a challenge with aligning the items within a navigation bar on my website. The list serves as a navigation bar and is contained inside the "inner header" div. While I was able to align the entire "nav" con ...

Is it possible to confirm whether or not ajax is being utilized?

Is this Ajax Request? Detecting Ajax in PHP and making sure request was from my own website I am working on a form for uploading images and utilizing the Ajaxform() function. $('#uploadformimage').ajaxForm({ beforeSend: function() { ...

What could be causing my carousel slider images to not adapt to different screen sizes?

I recently added a carousel slider to my website, and while it looks great on larger screens like desktops and laptops, I noticed that the images are not scaling properly when viewed on smaller screen widths. This has resulted in non-responsiveness which i ...

Tips for converting it into an array

Utilizing jQuery's $.post function to retrieve data from a php file (retrieved from mysql), the output appears as follows: data = [['12-25-2012',62],['12-26-2012',60]] Upon storing this data in a variable, it is saved as a string ...

Performing repeated insertion using a foreach loop

I am seeking a way to add multiple rows into a database table. This is the HTML code: <tr> <td style="display:none"><input type="text" rows="4" name="teste[]" value="<?php echo $produto8["Id"]; ?>"></td> <td><textar ...

smooth upward scrolling and superimposed elements

After exploring the question posed in this thread, I am puzzled as to why setting the slider's scroll direction to vertical does not result in smooth up and down scrolling. Could this issue be related to slick itself, or perhaps the accompanying CSS c ...