Event of Mouse Wheel - Speed/Impact

Exploring a new THREE.JS project, I am implementing a mousewheel scroll event to transition from 0 to 1 smoothly.

Nevertheless, my goal is to replicate the momentum effect seen on this website playdoh by merci Michael

So far, here's what I have accomplished:

this.R = 0
mouseWheel(dx, dy) {
    if (this.R < 0) {
        this.R = 0
        return
    }
    if (this.R > 1) {
        this.R = 1
        return
    }

    inertia.update(dy)
    this.R += dy / 45500
    let clamped = this.clamp(0, 1, this.R);

    // UPDATE THREEJS CAMERA POS
    this.dolly.cameraPosition = clamped;
    this.dolly.lookatPosition = clamped;
    this.dolly.update();
}
clamp(min, max, v) {
    if (v < min) {
        return min;
    } else if (v > max) {
        return max;
    } else {
        return v;
    }
}

The current implementation functions correctly but lacks the dynamic scrolling behavior observed in the provided example link. Scroll action abruptly stops instead of carrying on with velocity as desired.

Answer №1

How about trying a different approach?

this.dolly.cameraPosition += (clamped-this.dolly.cameraPosition)*0.5

instead of the original line:

this.dolly.cameraPosition = clamped;

You have the flexibility to adjust the transition speed by changing the value like 0.1 or 0.9.

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

Building a React.js application and fetching information with Ajax

In my quest to create a high-speed React.js application that functions as a game, I find myself in need of displaying real-time data. However, the traditional method of loading this data from the server using Ajax doesn't quite align with the reactive ...

Is there a different method to retrieve language bundles with next-i18next instead of using a customized Node server?

Currently, I am developing a Next.js application that will utilize i18next translations organized in the recommended file structure for bundles. For example: static/locales/en/common.js static/locales/de/common.js You can refer to this article: https://m ...

Exploring the differences in jQuery

Here is a snippet of my jQuery function: $(function() { $('.submitButton').click(function(){ $('input').each(function() { if ($(this).attr('min')) { if ($(this).val()<$(this).attr ...

Getting a URL to redirect after a successful login via an AJAX request in PHP

I've been trying to figure out how to redirect the URL after a successful login using an Ajax call in PHP. Can someone please review my code and point out any mistakes? Here is the content of the registration.php file located at http://localhost:8080 ...

Does __ only function with curried functions as intended? What is the reason for it working in this case?

I'm trying to figure out the reason behind the successful usage of __ in this particular code snippet : function editAddress (id, addressId, model) { return BusinessService .getById(id) .then(unless( () => checkUrlValue(add ...

Determine the minimum value of an object's keys by comparing them to a given number

Consider the following scenario: const list = { 1: "a", 10: "b", 20: "c", 30: "d", 40: "e" }; const value = 15; I am looking for an efficient way to compare the 'value' against the keys in the object and retrieve the corresponding va ...

AngularJS: when only one line is visible, the other remains hidden

Issue with AngularJS: Only One Line Displaying Instead of Both I am encountering an issue with my AngularJS code where only one of the elements is displaying on my page. function Today($scope, $timeout) { $scope.now_time = 0; (function update() { ...

Using Jquery's closest technique to target a class located outside of the parent div

I am having trouble accessing a class outside of its parent div $(document).on('click', '.delete_photo', function(event){ var del_id = $(this).attr('id'); $.ajax({ type:'POST', cache: false, url:&apo ...

"Trouble with jQuery not being triggered when there is a string in

New to the world of MVC and diving into jQuery for the first time, I am faced with a challenge. My goal is to populate text boxes in a partial view using jQuery that is placed within the parent view. Here are the relevant sections of the parent view: @ ...

Invoking a Vue method within a Laravel blade template

In my Laravel project, I have a blade that is loading a Vue component successfully. However, I am facing an issue where calling a method in the Vue component from a select box in the blade is not working as expected. Despite having a method call set up to ...

Struggling with implementing conditional validators in Angular2 form models. I have tried using myForm.setValidators(), but it doesn't appear to be functioning as expected

I have been experimenting with the model form in an Ionic/Angular2 project. My goal is to implement conditional validation on a form where users initially fill out 6 required fields, and then choose between 'manual' and 'automatic' proc ...

Starting a function will result in the return of its name

const [data, updateData] = React.useState({ default: () => fetchData(), defaultTab: " }); useEffect(() => { console.log(data, 'current data values') }, [data]) The issue at hand is that whenever setState is called, the API call d ...

Utilizing AJAX to transfer information into a modal window in CodeIgniter

I find it a little embarrassing to admit, but a few months ago I had asked the same question. Unfortunately, I failed to implement it with codeigniter back then. If you're curious, you can check out my old question. My current challenge involves upd ...

Prompt for confirmation in ASP.NET code-behind with conditions

I've searched around for a solution to this problem. Below is a representation of my pseudocode: bool hasData = ItemHasData(itemid); Confirm = "false"; // hidden variable if (hasData) { //Code to call confirm(message) returns "true" or "false" ...

Transform javascript classes into flash

Is there a way to transform a JavaScript class into Flash and implement it the same way as the original one? For example: var MyClass = function() { var exports = {}; var message = exports.message = function showMessage(msg) alert(msg); ...

Can you explain the significance of triple brackets (e.g. {{{ content }}}) in the context of Javascript/Typescript?

As I delve into the code of a fresh project in which I hope to contribute, I have come across numerous methods defined with triple brackets, like so: deinitialize() {{{ this.destroyed = true; $(window).off("resize", this.resize as () => void); ...

In the process of attempting to upload a .tsv file through the front end interface, I am encountering a challenge as the file remains stored on my server. What is the

I've got a function set up on my Express server that sends a file dependent on D3.JS. app.get('/dashboard', function(req, res) { var timestamp = utility.timestamp(); console.log('[' + timestamp + '] Request made to rend ...

What steps should I take to create a submenu?

Visit this website for more information. Looking to add a new submenu in the Services section under Office 365 Consulting, we have completed the backend work and now need to style it using CSS to resemble a submenu. Attempts at giving padding or margin res ...

Ways to retrieve data from response instead of subscription JSON in Angular 2/4

My Service : retrieveData(url,request) { return this.http.post(this.apiUrl+url,request).subscribe( (response) => {return response.json()} ); } My Component : ngOnInit() { this.data = this.dataService.retrieveData(&apos ...

How do I automatically redirect to a different URL after verifying that the user has entered certain words using Javascript?

I want to create a function where if a user input on the "comments" id matches any word in my FilterWord's array, they will be redirected to one URL. If the input does not match, they will be redirected to another URL. The checking process should onl ...