0

我通过 github 分叉到 rainyday.js,这是一个由 maroslaw 在此链接上制作的很棒的 javascript 程序:https ://github.com/maroslaw/rainyday.js 。基本上,我尝试获取他的演示页面和我自己的照片city.jpg并更改了适用的字段,以便我可以在本地运行它并最终在我自己的站点上运行它,但只有图片加载并且脚本本身没有开始运行。我对 html 和 javascript 很陌生,所以我可能会省略一些非常简单的东西,但这里是演示代码的脚本:

    <script src="rainyday.js"></script>
    <script>
        function getURLParameter(name) {
            return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,''])[1].replace(/\+/g, '%20'))||null;
        }

        function demo() {
            var image = document.getElementById('background');
            image.onload = function () {
                var engine = null;
                var preset = getURLParameter('preset') || '1';
                if (preset === '1') {
                    engine = new RainyDay({
                        element: 'background',
                        blur: 10,
                        opacity: 1,
                        fps: 30,
                        speed: 30
                    });
                    engine.rain([ [1, 2, 8000] ]);
                    engine.rain([ [3, 3, 0.88], [5, 5, 0.9], [6, 2, 1] ], 100);
                } else if (preset === '2') {
                    engine = new RainyDay({
                        element: 'background',
                        blur: 10,
                        opacity: 1,
                        fps: 30,
                        speed: 30
                    });
                    engine.VARIABLE_GRAVITY_ANGLE = Math.PI / 8;
                    engine.rain([ [0, 2, 0.5], [4, 4, 1] ], 50);
                } else if (preset === '3') {
                    engine = new RainyDay({
                        element: 'background',
                        blur: 10,
                        opacity: 1,
                        fps: 30,
                        speed: 30
                    });
                    engine.trail = engine.TRAIL_SMUDGE;
                    engine.rain([ [0, 2, 0.5], [4, 4, 1] ], 100);
                }
            };
            image.crossOrigin = 'anonymous';

            if (getURLParameter('imgur')) {
                image.src = 'http://i.imgur.com/' + getURLParameter('imgur') + '.jpg';
            } else if (getURLParameter('img')) {
                image.src = getURLParameter('img') + '.jpg';
            }

            var youtube = getURLParameter('youtube');
            if (youtube) {
                var div = document.getElementById('sound');
                var player = document.createElement('iframe');

                player.frameborder = '0';
                player.height = '1';
                player.width = '1';
                player.src = 'https://youtube.com/embed/' + youtube + '?autoplay=1&controls=0&showinfo=0&autohide=1&loop=1';
                div.appendChild(player);
            }
        }
    </script>

这是我命名我的背景并从目录中指定照片的地方。

<body onload="demo();">
    <div id="sound" style="z-index: -1;"></div>
    <div id="parent">
        <img id='background' alt="background" src="city.jpg" />
    </div>
</body>

整个rainyday.js 脚本的实际代码可以在这里找到:https ://github.com/maroslaw/rainyday.js/blob/master/rainyday.js

提前感谢您的任何帮助和建议!

4

0 回答 0