简体   繁体   English

在 wordpress 主题中插入 javascript 背景

[英]Insert a javascript background in wordpress theme

I want to put a javascript file as my background on my wordpress website.我想在我的 wordpress 网站上放一个 javascript 文件作为我的背景。 It is an animated background that is continuously runing (it's the matrix rain).这是一个持续运行的动画背景(它是矩阵雨)。 I don't know where should i start to insert the code, i have been looking on internet but there is no tutorial about inserting an animated background on a wordpress theme.我不知道我应该从哪里开始插入代码,我一直在网上寻找,但没有关于在 wordpress 主题上插入动画背景的教程。

Could you help me please?请问你能帮帮我吗? I think a lot of people are in my situation.我想很多人都和我一样。

Thanks:)谢谢:)

I take this matrix-rain library as an example https://sigstart.github.io/matrix-rain/ .我以这个矩阵雨库为例https://sigstart.github.io/matrix-rain/

First you have to save the file https://raw.githubusercontent.com/sigstart/matrix-rain/master/matrix.js as matrix-rain.js in the js folder of the theme.首先,您必须将文件https://raw.githubusercontent.com/sigstart/matrix-rain/master/matrix.js作为matrix-rain.js在主题的js文件夹中。

Then you have to include the JavaScript file.然后你必须包含 JavaScript 文件。

In functions.phpfunctions.php中。php

// Import moment.js
wp_enqueue_script('moment-min-js', 'https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.3/moment.min.js', array(), '1.0.0', false);
// Import matrix-rain
wp_enqueue_script('matrix-rain', get_template_directory_uri() . '/js/matrix-rain.js', array(), '1.0.0', false);

Then in the template where you want to show the background, for example single-post.php put this:然后在要显示背景的模板中,例如single-post.php

<canvas id="matrix"></canvas>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM