Is there a way to bring together scrolling effects and mouse movement for a dynamic user

If you want to see a scrolling effect, check out this link here.

For another animation on mouse move, click on this link(here).

Combining both the scrolling effect and the image movement might seem challenging due to different styles used in each template. In one front-end template, actual images are employed whereas image backgrounds are used in the other.

To achieve this combination, follow the code snippets below:

// JS code here

var zoom_value = 1;
var boxFullHeight = $('header').height();
var boxHalfHeight = $('header').height() / 2;
var domHeight = $('html').scrollTop();

//scrollController will check the value when scrolling up or down
var scrollController = 0;

//max number that the scroll happens before images change
var max_scrollController = 4;

//this will enable/disable the scrollbar after a certain period
var controller = 0;

... (JS Code Continues) ...

// CSS code here

html,body,header, #header_box, .image_box, img {
    height: 100%;
}
#firstbox{
  background: red;
    width: 100%;
}

#second_box{
  background: blue;
}

#third_box{
  background: black;
}

.general{
  width: 100%;
  height: 100%;
}

header {
    position: relative;
    overflow: hidden;
}
.image_box{
    position: absolute;
    width: 100%;
}
img{
    width: 100%;
}

.hide_image {
    visibility: hidden;
}

... (CSS Code Continues) ...
 
// HTML code here

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<body>
    <div id="firstbox" class="general">
        <header>
            <div id="header_box">
                <div class="image_box">
                    <img class="img1" src="https://cdn.pixabay.com/photo/2017/03/07/13/38/landscape-2124022_960_720.jpg" alt="image here">
                </div>
                <div class="image_box box2">
                    <img class="img2" src="https://cdn.pixabay.com/photo/2017/06/05/20/10/blue-2375119_960_720.jpg" alt="image here">
                </div>             
            </div>

        </header>
        <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Alias ut accusamus non error laboriosam in commodi ad, sint, neque voluptates deserunt magnam minima nulla officia nobis fugit enim optio assumenda.</p>
    </div>
    <div id="second_box" class="general">

    </div>

    <div id="third_box" class="general">

    </div>

</body>

Answer №1

To incorporate this functionality into your JavaScript, simply follow these steps:

$('.container').on('mousemove', function(event){
  let x = event.originalEvent.x,
      y = event.originalEvent.y,
      width = this.offsetWidth,
      height = this.offsetHeight,
      moveX = width / 2 - x,
      moveY = height / 2 - y;

  $(this).css({
    'transform': 'scale(1.5) translate(' + moveX/20 +'px, ' + moveY/20 +'px)'
  });
});

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

Exploring the functionality of Protractor testing in combination with Angular 2, focusing

I am currently developing an Angular 2 application and I require some information regarding unit testing with Protractor. Previously, in Angular 1, we were able to check for things like: element(by.css('[ng-click="myFunction()"]')) in our test ...

What is the process for extracting HTML tables from files using pandas?

I am a beginner at pandas and I am attempting to extract data from HTML files. How can I convert multiple HTML tables like the ones below: PS4 Game Name | Price GoW | 49.99 FF VII R | 59.99 XBX Game Name | Price Gears 5 | 49.99 For ...

Missing 'id' property in ngFor loop for object type

I'm currently learning Angular and I've been following a code tutorial. However, despite matching the instructor's code, it doesn't seem to be working for me. When I try to compile the following code, I receive an error message stating ...

How about this: "Unveil the beauty of dynamically loaded

var request = new Request({ method: 'get', url: 'onlinestatusoutput.html.php', onComplete:function(response) { $('ajax-content').get('tween', {property: 'opacity', duration: 'long&apos ...

Javascript: Anticipating a Return from an Argument

I am currently working on a function that requires an attribute to respond before proceeding with its process. The function call is structured like this : processResult(getResult()); The issue lies in the fact that the getResult function takes some time ...

How can I effectively save data to a session using connect-redis?

I am looking to save the username of an account into session storage. I am currently using node.js with the expressjs framework and have attempted to utilize connect-redis for storing sessions, following a tutorial on expressjs. Can someone please guide ...

Show recent posts on individual post page while excluding the currently active single post

Currently, I am in the process of working on a WordPress website. I have created a page that displays all the news headlines (post titles). When users click on a title, they are taken to the specific post's page. To enhance user experience, I would l ...

What could be causing JavaScript fetch to only send OPTIONS requests instead of the expected calls?

I'm having an issue with my AJAX request using javascript fetch. It's only sending an OPTIONS call and not proceeding to make further calls. What's strange is that the response header seems fine, and $.ajax is working as expected. Check out ...

The Ajax form is failing to retrieve the expected PHP data

My login system uses a combination of ajax and php. The form validation is handled through javascript, with the form data then being sent to php for database checks. In the past, this method has worked well for me, but in this instance, it seems 'NOTH ...

Angular 14 troubleshooting: Issues with using getRawValue() in IndexOf function

In this scenario, I have a straightforward Person interface defined as: import { FormArray, FormControl, FormGroup } from '@angular/forms'; import { Address } from './address'; export class Person { id: FormControl<number>; n ...

The property 'licenses' has incompatible types. The type 'License[]' cannot be assigned to type 'undefined' in the getServerSideProps function while using iron-session

I am encountering an issue with red squiggly lines appearing on the async keyword in my code: Argument of type '({ req, res }: GetServerSidePropsContext<ParsedUrlQuery, PreviewData>) => Promise<{ props: { admin: Admin; licenses?: undefined ...

Styling the file input type in AngularLearn how to customize the

I've come across numerous queries on how to style an input type file, but I'm struggling to implement it in an angular context. So, what is the best way to customize the appearance of an input type file within an angular application? Below is t ...

The error message indicates that the HTTP status code "600" is not a recognized response after an ajax submission

After submitting the form, I encountered this error message: An error occurred in Response.php line 462: The HTTP status code "600" is not recognized. $("#personal_info_form").submit(function(event) { var name = $("#Name").val(); var email = ...

Creating a Custom Rule for Checkbox Validation using jQuery

Can the jQuery Validation plugin be used to validate custom values on checkboxes, rather than just True or False? For instance: <input id="test" type="checkbox" name="test" value="something"> I am struggling to find a method that can check if &apo ...

Ways to create a smooth transition in element height without a known fixed target height

Is it possible to create a smooth height transition for an element when the target height is unknown? Replacing height: unset with height: 100px allows the animation to work, but this presents a problem as the height needs to be based on content and may v ...

Utilize the inverse mapping method along with conditional statements inside a mapping function

When looping through the categories using categories.map(), I am trying to reverse the elements of the categories and also check for category.isFeatured before creating a link. However, I am unable to use an if statement in this scenario. const Header = ...

Click event triggers nested bootstrap collapse

As a beginner in bootstraps and coding, I am currently experimenting with opening the main bootstrap panel using an onclick event that includes nested sub panels. Here is my index.html file containing the panels and the button; <link href="https://m ...

The JavaScript function modifies the value stored in the local storage

I'm in the process of developing a website that requires updating the value of my local storage when certain JavaScript functions are executed. Currently, I have this code snippet: localStorage.setItem('colorvar', '#EBDBC2'); I&ap ...

Tips on maximizing efficiency in number game coding

Seeking to create a number using a specified set of 6+ inputs. For instance, aiming for the number 280 with inputs [2,4,5,10,30,50,66], the desired output format would be something like this: ((2+5) * 4 * 10). Each input number can only be used once per s ...

The navigation bar appears to have a different width on mobile view specifically on one page

I created a mobile view navigation that appears correctly on two out of three pages. It spans the full 100% width as intended, but on one page it extends beyond that and causes the layout to look distorted due to the larger navigation bar. I'm not sur ...