Coder Social home page Coder Social logo

Multiple .snowfall() about jquery-snowfall HOT 5 CLOSED

loktar00 avatar loktar00 commented on July 18, 2024
Multiple .snowfall()

from jquery-snowfall.

Comments (5)

 avatar commented on July 18, 2024

For what I need I have figured a dirty fix for the time being.. as I want .snowfall() to be on different div's which aren't on the screen at the same time this bit of code works for me

// Snow Fall
var outside = jQuery('.scene3 .outside');
jQuery(function () {
    outside.data('switch', 'on');
});
jQuery(window).scroll(function () {
    if (jQuery(document).scrollTop() > 12500) {
        if (jQuery(outside).data('switch') == 'on') {
            jQuery(outside).data('switch', 'off');
            //Clear Scene1
            jQuery('.scene1').snowfall('clear');
            //Start Scene3
            jQuery(outside).snowfall({
                image :'/wp-content/themes/christmas/images/snow.png',
                flakeIndex: 28,
                minSize: 11,
                flakeCount: 10,
                maxSize:15
            });
        }
    } else {
        if (jQuery(outside).data('switch') == 'off') {
            jQuery(outside).data('switch', 'on');
            //Clear Scene3
            jQuery(outside).snowfall('clear');
            //Start Scene1
            jQuery('.scene1').snowfall({
                image :'/wp-content/themes/christmas/images/snow.png',
                flakeIndex: 28,
                minSize: 11,
                maxSize:15
            });
        }
    }
});

from jquery-snowfall.

Silarn avatar Silarn commented on July 18, 2024

I recently made a pull request to address this problem.

It does so by moving the flakes array to a global scope (within the plugin). Then, during creation and garbage collection, I carefully remove and fill in the associated flake ids from the global flakes array sorted by the id number.

This allows every snowflake to have a unique id so that the animation code works correctly and should also fill in old ids of erased flakes rather than continuing to create bigger and bigger id numbers.

from jquery-snowfall.

Silarn avatar Silarn commented on July 18, 2024

The pull request is #28 but I have not yet ported the jQuery code to the 'stock javascript' version.

from jquery-snowfall.

Silarn avatar Silarn commented on July 18, 2024

Both versions of the script should now work with multiple elements with my changes, see #28

from jquery-snowfall.

loktar00 avatar loktar00 commented on July 18, 2024

👍 thanks to the hard work by @Silarn this should be resolved and has been merged in.

from jquery-snowfall.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.