Divs are shown as the user scrolls, not only when they are in view

Currently, I am in the process of enhancing my online portfolio by integrating a bar graph feature. However, I have encountered an issue with its functionality. The goal is for the bar graph to display only when it comes into view during scrolling. Although I have managed to make it work properly, the effect triggers immediately upon scrolling rather than at the point when it enters the user's view. Could someone please guide me on what I might be doing wrong in this setup? Additionally, it is worth mentioning that I am utilizing a plugin named LiveQuery on my website.

HTML:

<div id="section-three">
        <div id="web-head">
            <h2>Web Development</h2>
            <br>
            <p><i>Code, code, and more code!</i></p>
        </div>
        <div id="web-graph">
            <div id="html-bar">
                <p>HTML</p>
                <div id="html">
                </div>
                <div class="clear"></div>
            </div>

            <div id="css-bar">
                <p>CSS</p>
                <div id="css">
                </div>
                <div class="clear"></div>
            </div>

            <div id="jq-bar">
                <p>JQuery/JavaScript</p>
                <div id="jq">
                </div>
                <div class="clear"></div>
            </div>
        </div>
    </div>

CSS:

    /*SECTION THREE CODE*/

#section-three {
    min-width: 100vw;
    width: 100%;
    min-height: 500px;
    height: 100%;
    background-color: #000000;
    overflow: hidden;
    text-align: center;
}

#web-head {
    max-width: 70vw;
    width: 100%;
    min-height: 100px;
    height: 100%;
    margin-top: 2%;
    margin-left: auto;
    margin-right: auto;
    color: white;
}

#web-head h2 {
    font-weight: normal;
}

#web-head p {
    color: #808080;
}

#web-graph {
    min-width: 85vw;
    width: 100%;
    min-height: 300px;
    height: 100%;
    display: flex;
    flex-direction: column;
    text-align: left;
}

#web-graph p {
    float: left;
    max-width: 14vw;
    width: 100%;
    min-height: 50px;
    height: 100%;
    margin-left: 2%;
    margin-top: 37.5px;
    color: white;
}

#html-bar {
    flex: 1;
}

#html {
    min-height: 50px;
    height: 100%;
    max-width: 70vw;
    width: 0;
    float: left;
    margin-top: 25px;
}

#html.active {
    background-color: #808080;
    transition: all ease-in-out 1s;
    min-height: 50px;
    height: 100%;
    max-width: 70vw;
    width: 70%;
    float: left;
    margin-top: 25px;
}

#css-bar {
    flex: 1;
}

#css {
    min-height: 50px;
    height: 100%;
    max-width: 70vw;
    width: 0;
    float: left;
    margin-top: 25px;
}

#css.active {
    background-color: #808080;
    transition: all ease-in-out 1s;
    min-height: 50px;
    height: 100%;
    max-width: 65vw;
    width: 65%;
    float: left;
    margin-top: 25px;
}

#jq-bar {
    flex: 1;
}

#jq {
    min-height: 50px;
    height: 100%;
    max-width: 70vw;
    width: 0;
    float: left;
    margin-top: 25px;
}

#jq.active {
    background-color: #808080;
    transition: all ease-in-out 1s;
    min-height: 40px;
    height: 100%;
    max-width: 35vw;
    width: 35%;
    float: left;
    margin-top: 25px;
}

JQuery:

    $(document).ready(function () {
    $('#jq-bar:visible').livequery(function () {
        $('#html').addClass('active');
        $('#css').addClass('active');
        $('#jq').addClass('active');
    })             
});

I should also note that I had previously tried linking it to whenever a div or an item with a certain ID or class showed, it will trigger the function, but it still didn't work, unfortunately. If someone would be able to point me in the correct direction, I would highly appreciate it. Thank you!

Answer №1

Your selector will target elements as soon as the page loads:

 $(document).ready(function () {
    $('#jq-bar:visible')

Taken without shame from W3C:

Definition and Usage The :visible selector selects every element that is currently visible.

Visible elements are elements that are not:
Set to display:none
Form elements with type="hidden"
Width and height set to 0
A hidden parent element (this also hides child elements)

If you want to determine when something becomes visible, consider using methods like scroll top to manage classes.

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

Position the div element beside the image, rather than below it

I am having an issue with Bootstrap where the card I want to display on the right of an image is appearing below it instead. I attempted to use the display: inline-block property, but unfortunately, that did not solve the problem. I also explored other so ...

Add option button

Is there a way to dynamically add radio buttons using jQuery or JavaScript and save the data into a database? I have successfully appended input types such as text, textarea, checkbox, and select with options. Here is my code: <!DOCTYPE html> < ...

What is the method for customizing the default dropdown color of a bootstrap 4 selectpicker?

In my form, there are single and multiple dropdown selects. To keep things simple, I use the selectpicker class for both types. However, I want to customize the default grey color for Bootstrap 4 Dropdown with the selectpicker class to a clear color. Which ...

Unable to provide feedback on the input elements

ISSUE: Unable to provide input in the input fields // Enable dragging for the DIV element: dragElement(document.getElementById("mydiv")); function dragElement(elmnt) { var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0; if (document.getElementB ...

Ways to avoid unintentional removal of contenteditable unordered lists in Internet Explorer 10

How can I create a contenteditable ul element on a webpage while avoiding the issue in Internet Explorer 10 where selecting all and deleting removes the ul element from the page? Is there a way to prevent this or detect when it happens in order to insert ...

JavaScript unexpectedly populating array with unnecessary empty objects

During my attempt to create a calculator, I encountered an error while testing. After entering a number and selecting one of the operation buttons, I ran a console.log test and discovered 3 extra arrays lingering without purpose. You can find the JSFiddle ...

When an image is placed inside a parent div, the link should extend to the entire width of the div, rather than just hovering over

Essentially, I have a div that spans the entire width of its container, inside it is an image link. The image's width is set to adjust automatically with a fixed height of 600px. The link covers the whole width of the div, which in this case is the wi ...

Does the zoom value in the HTML file adjust when I zoom in or out on the Google Map?

I'm uncertain if my question is sufficiently clear. Here's my dilemma: I've been utilizing the gmplot module in Python and I'm interested in adjusting the grids to be scalable based on the zoom level of the Google Map. However, being u ...

Following the parsing of the list of months, the sequence undergoes a

After receiving the JSON encoded object from the server side in PHP MONTHLY_FORMAT, I am reading that object in jQuery as: var MONTHLY_FORMAT = '<?php echo $MONTHLY_FORMAT; ?>'; When checking the console output, it looks like this: {"0 ...

`Is there a way to choose several radio buttons with varying names using just one label?`

Is there a way to choose multiple radio buttons with different names using just one label? Here's an example of what I'm attempting to accomplish... <input id="1A" type="radio" name="first" value="A">firstA<br> <input id="1B" typ ...

Emulate an AngularJS ng-click action

My website has HTML code with three buttons: <button ng-click='showStats(player.data,0)'>Death Match</button> <button ng-click='showStats(player.data,1)'>Champions Rumble</button> <button ng-click='sho ...

Illuminate a group of items when hovering over them

While attempting to change the color of 1 to 5 elements on mouse hover based on the data-rating tag, I am encountering a few issues. The data is retrieved correctly, but there are some problems: The function is being called 5 times each time there is a ho ...

jQuery AJAX callback fails to trigger

I am encountering an AJAX request in my code: $.ajax({ url : "proxy.php", type : "POST", data : xmlData, contentType : "application/x-www-form-urlencoded", processData : false, success : function(data) { // successful response ...

How to submit a textarea with the enter key without needing to refresh the page

I'm attempting to handle the submission of a textarea when the user hits the enter key, storing the text in a variable, then swapping out the form with the text and adding a new form at the end, all without refreshing. I had success doing this with an ...

Second update in Bootstrap datetime picker not functioning

I am trying to create a start date picker called dropoff_date_picker that is dependent on another date picker named pickup_time_picker. Initially, when I select a date from the pickup_time_picker, the dropoff_date_picker start date gets updated and functio ...

Having difficulty transferring serialized arrays from HTML to lower PHP files

I am attempting to transfer an array of checkbox inputs from an HTML page to an initial PHP file which creates a new layout for a page and then calls another PHP file to populate it. However, I am encountering issues with the serialization and unserializat ...

I have multiple div containers on my webpage, and I'm looking for a way to dynamically load data into a specific div without having to refresh the entire page using PHP and Code

Is there a way to load data into only the second div tag when clicking on a link, without refreshing the entire page? I want to ensure that the first and third div tags remain static while allowing the second div tag to be dynamic. <div class="first" ...

What is causing the .sr-only class to malfunction in Bootstrap 5?

Currently, I am working on creating a one-page form using Bootstrap 5: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge& ...

Indicator malfunctioning on Carousel feature

I created a carousel containing six photos, but I am encountering an issue with the carousel indicators below. The first three indicators work correctly – when clicked, they take me to the corresponding slide (e.g., clicking the 1st indicator takes me ...

Troubleshooting problem with presenting real-time data in a Bootstrap Carousel using PHP

Currently, I am in the process of developing a dynamic events calendar to showcase on a website homepage. The information displayed on this calendar is retrieved from a database using PHP. Additionally, I have implemented the Bootstrap framework (version 4 ...