Initiate an animation upon reaching a designated element using Jquery scroll event

Hey there! I've been trying to create an animation without using any plugins, but unfortunately, I haven't had much luck so far.

Here's the code I've been working on. If anyone can help me figure this out, I'd really appreciate it!

I'm hoping to get the animation to start only when the user scrolls down to a certain point. You can find my codepen here: https://codepen.io/abcari/pen/pdyPjy

$(window).scroll(function () {

    if ($(".skill-level").is(".htcss:visible")) {

        $(".htcss").animate({ width: $(".htcss").data('width') + "%" }, 
2500);

    }
});

Answer â„–1

Here is a more straightforward example:

$(window).on("scroll", function(){
  if($(window).scrollTop() + $(window).height() - 100 >= $(".target").offset().top){
    alert("You have reached the target");
  }
})
body{
  padding-top: 150vh;
}

.target{
  background: blue;
  width: 100%;
  height: 50px;
  margin-bottom: 500px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="target">
</div>

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

Choose content within an HTML tag and modify its appearance

<body> This is text1 <div> This is text2</div> </body> I'm looking to style the text1 only. I attempted to use body{ color:red; } but both text1 and text2 ended up turning red. What I really need is something like th ...

Menu options are unresponsive to clicks in the dropdown

Need help fixing my dropdown menu issue. Whenever I hover over the dropdown, it disappears before I can click on any items. Here is a snippet of the code causing the problem: #navContainer { margin: 0; padding: 0; padding-top: 17px; width: 220 ...

Determine the number of lines in a textarea, taking into account both manual

I have a textarea that I need to validate for input exceeding 6 rows. My JavaScript code works perfectly by checking for scrollbar presence, indicating more than 6 lines of input. However, how can I achieve the same validation using PHP in case JavaScript ...

Ways to send a JSON object to an MVC controller

I am looking to pass 2 arguments to my controller: an id and an object[]. Below is the code for my controller: [HttpPost] public string SaveCoordinates(string Id, object[] pFrame) { string result = "ERROR"; if (pFrame != null) { try ...

What could be causing my Leaflet popup to suddenly close?

My feature allows users to search for a marker and zoom to its location, triggering the popup to open. Everything is functioning correctly, except that the popup closes after the function executes. I am struggling to pinpoint what is causing the popup to c ...

I keep receiving an error message when trying to use slide() in jQuery

Can someone help me understand why I am getting an error with this slide() function? $(this).hide("slide", { direction: "down" }, 1000); Error: Message: Object doesn't support this property or method Thanks, Jean ...

Using JavaScript to toggle the iron-collapse property

I've implemented multiple <iron-collapse> elements with unique IDs, each one corresponding to a <paper-icon-button>. On screens wider than 650px, I can interact with the <iron-collapse>s using their respective buttons. But on narrow ...

Using jQuery to Populate a Table with JSON Data

Despite my extensive search and analysis of similar questions on this forum, I have reached a roadblock. My script is failing to load data from a Json file into the table I am trying to create, even after closely following the jquery API guidelines. Any as ...

Issue Encountered While Trying to Load Images on Local Host Test Server

I have encountered a strange issue that I can't seem to explain. Currently, I am developing an AngularJS website for my family that includes integration of data from different web services. One section of the site involves fetching photos from our Fl ...

What is the reason behind genNewColor function's malfunction?

I'm having trouble with this code that is supposed to generate a random color. The CSS formatting works perfectly, but I suspect there might be an issue with the function itself. When I try to run the code, it doesn't produce any error messages â ...

Achieving a persistent footer at the bottom of the page within Material Angular's mat-sidenav-container while using the router-outlet

I am looking to keep my ngx-audio-player fixed at the bottom of the screen, similar to what you see on most music streaming websites. I currently have a structure with divs and various elements for dynamic content and playing music. The issue is that the ...

Issue with the read more button inoperative for two specific paragraphs

Upon trying to implement 2 or more "Read More" buttons on my website for users to view snippets of content before downloading, I encountered an issue with the functionality only working on the first paragraph and not the subsequent ones. Despite ...

The content inside the HTML body doesn't fully encompass the dimensions of the mobile screen

I am working on making my application flexible by using 100vw width and 100vh height for the components. Everything displays perfectly in any resolution on a computer browser, but when viewed on a mobile device, an empty background is drawn below the bod ...

Adjusting the width of innerHtml within a React router link to match the parent element's width

My current challenge involves a table where a cell is represented as a link. Within this setup, I am incorporating html content into the text of the link: <TableCell align="left" classes={{root: classes.cellPadding}}> <Link className={classes.l ...

The user uploads an image to the server, which is then assigned as the background-image for a div element

I am in search of a straightforward method to allow users to upload an image to my server and then use that uploaded image as the background-image for a div element. I need the image to be actually uploaded to the server rather than just displaying a local ...

How to send parameters to the jquery .css() method

I'm attempting to create hyperlinks that can dynamically set inline styles for different elements on a webpage. I have managed to save the element and attribute settings in hidden span elements and retrieve them to display in an alert dialog. However, ...

Side Menu with Fixed Position Created with Tailwind CSS

Can anyone help me create a social media sidebar that stays fixed on the bottom right side of the screen, regardless of its size? Currently, the sidebar moves when I scroll down, but I want it to remain in place. How can I achieve this fixed positioning? ...

"Using Vue 3 to teleport content to a specific element and swap out existing

I've successfully implemented the use of Vue 3 teleport to display elements within a div. Although teleport adds items to the specified element, it doesn't replace existing elements in the div. Is there a way to configure teleport to replace th ...

Tips for creating a responsive background image that adjusts after resizing the window to a certain width

Is there a way to create a responsive background-image that adjusts when the window is resized to a specific width, similar to the main image on ? ...

What is the best way to initiate a change event using JavaScript?

I am attempting to enable my 4th checkbox automatically when there is a new value in the textbox (myinput). If the textbox is empty, I want to disable it. Currently, you have to tab out before the change event is triggered. Also, how can I check for an e ...