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

Applying CSS transformations to scale up a div within its parent body

Having an issue with formatting an anchor link using transform scale attributes on hover. The link is inside a div that's aligned to the right, and I want it to enlarge when hovered over. However, this increase in size also affects the parent div, ca ...

Determine which checkboxes are checked using jQuery

Is there a way to identify which checkboxes are checked after clicking on a specific button in a scenario where I have multiple checkBoxes created under a single div with data-role="controlgroup"? I am using JQuery for this task and need the best approac ...

Enhancing Bootstrap Carousel with various effects

My exploration of the web revealed two distinct effects that can be applied to Bootstrap Carousel: Slide and Fade. I'm curious if there are any other unique effects, such as splitting the picture into small 3D boxes that rotate to change the image? ...

What is the process for finding GitHub users with a specific string in their name by utilizing the GitHub API

I'm looking to retrieve a list of users whose usernames contain the specific string I provide in my query. The only method I currently know to access user information is through another endpoint provided by the GitHub API, which unfortunately limits t ...

What is the best way to prevent the table from being added again once it has been displayed?

I'm faced with the task of displaying an HTML table in a popup window when a button is clicked, using Bootstrap modal functionality. This scenario is similar to a preview function where user input is displayed in a table when a preview button is click ...

Create a Bootstrap jumbotron that is centered and only half of the width

I have a unique password reset method here: Jumbotron-Form-Bootstrap-My-Attempt Displayed below is the code from the image above: <div class="container"> <div class="jumbotron"> <br><br> <h2>Forget Passwo ...

JavaScript enables users to store over 5 megabytes of data on their client devices

Is there a way to store more than 5mb in the client browser? I need this functionality across various browsers including Firefox, Chrome, Internet Explorer, Safari (iOS), and Windows Phone 8 Browser. Initially, localStorage seemed like a viable option as i ...

I am receiving an undefined value when using document.getElementsByClassName

<canvas id="can" height="500px" width="1200px"></canvas> <div class="name"> <h1>LEONARDO</h1> </div> <script> var name=['WATSON','LEONARDO',"SMITH","EMILY"] var counter=0 var dat ...

What is the best way to invoke a function that is declared within a React component in a TypeScript class?

export class abc extends React.Component<IProps, IState> { function(name: string) { console.log("I hope to invoke this function"+ name); } render() { return ( <div>Hello</div> ); } } Next, can I cal ...

What is the process for requiring web workers in npm using require()?

I have a setup using npm and webpack, and a part of my application requires Web Workers. The traditional way to create web workers is by using the syntax: var worker = new Worker('path/to/external/js/file.js'); In my npm environment, this metho ...

Ways to automatically display the date upon loading the view

I have integrated a plugin with Angular, which is essentially an extension. Upon loading the view, only an empty input is visible. Clicking on the input reveals a calendar with today's date displayed. My objective is to automatically load today&apos ...

Make sure to include the target blank attribute in your custom PHP code for

Is there a way to open a link in a new window? <?php if(get_option_tree('rss')) { ?> <a href="<?php get_option_tree('rss',$theme_options,'true'); ?>" id="rss" title="RSS" class="tt_top"></a><?php } ...

Arranging sibling buttons to wrap seamlessly like text

Is there a way to turn every syllable of a specific phrase into clickable buttons while maintaining regular text wrapping behavior? For reference, in the first image each syllable is plain text, in the second they're wrapped in <span>, and in t ...

Adjust the code to enhance the functionality of web components in Sharepoint

I recently came across some code online that I'm trying to modify in order to add an expanding button next to a web part on my Sharepoint site. However, the problem is that by default, all web parts are already expanded and require a click to collapse ...

Bootstrap Progress Animation Not Scaling Properly

I am encountering an issue with my Bootstrap 2.3 progress bars. They are supposed to show async file reads and be animated by updating their CSS properties using jQuery. However, the problem I'm facing is that the scale seems to be off - when the prog ...

unable to render the JavaScript code

Utilizing JavaScript post an ajax request to showcase the data in a div using new JS content. The example code is provided below: //ajax call from a.jsp var goUrl = "/testMethod/getTestMethod; var httpRequest=null; var refreshCont ...

Steps for triggering the material-ui menu to appear on hover of a button

I attempted to implement the following code without success. I was able to achieve it using plain CSS, but I need to utilize the makeStyles function provided by material-ui. My goal is to display a drop-down list of items when a user hovers over the butto ...

Accessing node postgres and fetching combined fields with duplicate names

Currently, I am developing a node.js application that utilizes the pg package to connect to a PostgreSQL database. The problem I am encountering involves querying data using a join statement and finding that fields from one table overwrite those from anoth ...

Running NodeJS scripts with ElectronJS is not possible

Goal I'm facing a challenge with executing my separate scripts located in the project/api folder. Let's take test.js as an example, where I am exporting it using module.exports. When I run my electron window and create a JavaScript file with a f ...

What is the best way to ensure consistent spacing between columns in a Bootstrap 3 grid layout, similar to the spacing on the left and right sides?

Is there a way to achieve equal spacing between all blocks in a row, similar to the left and right padding that Bootstrap automatically applies? Currently, Bootstrap adds padding to all columns on both sides, but does not render extra spacing on the left s ...