What is the best way to adjust the height and width of a div when it comes into view through scrolling?

How can I automatically and frequently change the size of my div when it is scrolled into view?

HTML

<div id="contact" class="fadeInBlock">
    <div class="map">
        <div class="pointer">
            <div class="dot"></div>
        </div>
        <div class="address">
            <address></address>
        </div>
    </div>
</div>

(The div that will change height and width is the .pointer).

JS

$(function() {
    $(window).load(function() {
        $('.pointer').css({"width": "60px", "height": "60px"});
    });
});

I have only addressed changing the width and height. If there is any confusion, please let me know so I can clarify further.

Answer №1

JavaScript

$(document).ready(function() {
    $(window).on('load', function() {
        $('.pointer').css({'height':($(window).height())+'px'});
    });
});

Answer №2

If you're looking for a way to create a bouncing effect with width and height, one approach is to store the animation points and loop through the animate function multiple times.

While others may have provided strategies for the scroll event, I wanted to address your specific request for the bouncing effect as well.

I hope this solution proves helpful,

Sincerely, Tim

$(document).ready(function(){
    $("button").click(function(){
        $("div").animate({
            opacity: '0.5',
            height: '150px',
            width: '150px'
        });
        $("div").animate({
            opacity: '0.5',
            height: '50px',
            width: '50px'
        });
        $("div").animate({
            opacity: '0.5',
            height: '100px',
            width: '100px'
        });
        $("div").animate({
            opacity: '0.5',
            height: '75px',
            width: '75px'
        });
        $("div").animate({
            opacity: '0.5',
            height: '200px',
            width: '200px'
        });
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<button>Start Animation</button>
<div style="background:#98bf21;height:100px;width:100px;position:absolute;"></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

What is the method for retrieving the name of the 'Autocomplete' component in Material UI?

Currently, I am faced with the challenge of working on multiple Autocomplete MUI components and am in the process of creating a "generic" event handler that will utilize the useReducer hook to manage the state. The issue lies in the fact that the onChange ...

The autofocus feature on the textarea in Angular Material Dialog seems to be malfunctioning

Within a web app, I am utilizing the Dialog component from Angular Material. The Dialog consists of only a textarea that is initially empty. I aim to automatically focus on the textarea when the user opens the modal dialog. How can I achieve this? Despite ...

Encountering an Unexpected Token Error While Parsing JSON with jQuery

Utilizing the Envato API with jQuery to collect user stats is my current project. An example JSON response that I will display is as follows: { "new-files-from-user":[ { "thumbnail":"http://3.s3.envato.com/files/60560.jpg", "tags":"", "use ...

Create a personalized button | CKEditor Angular 2

I am currently working on customizing the CKEditor by adding a new button using the ng2-ckeditor plugin. The CKEditor is functioning properly, but I have a specific requirement to implement a button that will insert a Rails template tag when clicked. For ...

Prevent the Rain from descending

Looking for a way to toggle a particle emitter on or off, I've encountered memory leaks with my Reactjs code that generates rain/snow particles using the canvas element. Despite attempts to stop the animation properly, it seems to be projecting a new ...

Establish a table containing rows derived from an object

I am currently dealing with a challenge in creating a table that contains an array of nested objects. The array I have follows this schema: array = [ { id: 'Column1', rows: { row1: 'A', row2 ...

Error: The jQuery TableSorter Plugin is unable to access property '1' as it is undefined

I've been attempting to utilize the jquery table sorter plugin, but I keep encountering an error when trying to sort the table. The error message I'm receiving is: cannot read property '1' of undefined This is the HTML code I have: ...

Is it a problem with Cucumber Js callbacks or a feature issue?

I would like to create a scenario similar to this: Scenario: initialize new Singleton When an unmatched identity is received for the first time Then create a new tin record And establish a new bronze record And generate a new gold record This s ...

Tips for beginning with running vue js examples/demos

Is it possible to test my local server side REST endpoints by using the demo here? I'm not sure where to start - any guidance on how to edit and try out the demo? For example, I've cloned this repository from https://github.com/pespantelis/vue-t ...

Tips for managing the return value of a PHP function in AJAX requests

Looking for some help with inserting HTML form data using PHP and Ajax. Below is the code I've written: <!DOCTYPE HTML> <html lang="en"> <head><title>Ajax Test</title> <meta charset="utf-8" name="viewport" con ...

IE8 - Unable to use rgba()

I'm currently facing an issue with RGBA() manipulation in jQuery while using IE 8. Here's the code I have so far: $('.set').click(function (e) { var hiddenSection = $('div.hidden'); hiddenSection.fadeIn() . ...

How can I arrange individual events in agendaWeek view on FullCalendar.io and then merge them all into one line?

I am using Fullcalendar.io version 2 When I switch to the agendaWeek mode, all my events are displayed on one line in each day square. As a result, the more events I have, the thinner the event blocks become. Is there a way for me to display only one eve ...

What specific files from the Kendo core are required for utilizing Mobile and Angular functionalities?

After browsing through similar questions, I couldn't find a solution. Currently, I am experimenting with Kendo (open source core for now) in a Visual Studio Cordova project. Initially, disregarding Cordova, I am focusing on setting up a basic view wit ...

Is there a way to generate a distinctive curved design using CSS for a

I am currently using CSS and div elements in an attempt to create these particular lines: https://i.stack.imgur.com/Ytowq.png .line { width: 1px; height: 100px; background-color: black; position: absolute; border-radius: 50%/100px 1 ...

The request to access /test.php has resulted in an error (404) indicating that the file cannot be found

Disclaimer: I am completely new to php. I recently followed a tutorial on creating a php script that captures input from a sign-up page (html) and saves it in a database (mysql/Wamp). However, when I attempted to test the functionality, I encountered the ...

CSS Animation Effect on Transparent PNG Image

Today, while working on my website, an interesting CSS effect came to mind. I vividly remember seeing it a few months ago, but unfortunately, I couldn't find it among my bookmarks. The website featured a captivating design with a prominent logo that ...

Performing an AJAX POST request in Laravel

I'm struggling with getting this ajax call to work, and I can't seem to figure out what's going wrong. View (html) <div class="col-sm-6 col-xs-3 pl0" style="margin-left: -5px;"> <button class="btn btn-primary visible-xs" n ...

Tips for Importing HTML Table Data Line by Line into SQL Table

I have the following code here. I am looking to insert HTML table data row by row into an SQL database. However, with this current code, only the last row is being stored in the database table. I believe I need to implement a loop to read the data from e ...

Using jQuery to add a timed slide effect to an element

After the page loads, I want an element to slide left after 10 seconds without disappearing from the page completely. The goal is for it to move 200px to the left and then return to its original position when clicked. I'm unsure about how to set the ...

Looking to invoke a jQuery ajax page method

Just diving into jQuery and looking to execute a method at specified intervals. $(document).ready(function pageLoad() { setTimeout('runMethod()', 10000); }); (function runMethod() { $.ajax({ type: "POST", url ...