我尝试使用jquery和electron framework一起使用electron fiddle。但是jquery似乎不能正常工作,动画也不能执行。示例如下:https://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_animation1
主文件.js
// Modules to control application life and create native browser window
const {app, BrowserWindow} = require('electron')
function createWindow () {
// Create the browser window.
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true
}
})
// and load the index.html of the app.
mainWindow.loadFile('index.html')
// Open the DevTools.
// mainWindow.webContents.openDevTools()
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)
// Quit when all windows are closed.
app.on('window-all-closed', function () {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', function () {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
索引.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
<link rel="stylesheet" type="text/css" href="./styles.css">
<script>window.$ = window.jQuery = require('https://code.jquery.com/jquery-3.3.1.slim.min.js');</script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("div").animate({left: '250px'});
});
});
</script>
</head>
<body>
<button>Start Animation</button>
<div style="background:#98bf21;height:100px;width:100px;position:absolute;"></div>
<script>
// You can also require other files to run in this process
require('./renderer.js')
</script>
</body>
</html>
单击按钮后,没有任何React。
2条答案
按热度按时间brc7rcf01#
通常你会通过
npm install jquery
将electron安装到你的node_modules
文件夹中,并要求它在你的renderer.js
中。属于renderer.js内部。通过这种方式,您可以在本地拥有它,并且yiu不再依赖于外部CDN。
zkure5ic2#
在2022年,我就是这样让它运转起来的。
安装JQuery
使用
script
标记将jquery添加到index.html
文件中。src
应该是node_modules
文件夹中jquery的路径现在,JQuery将在渲染器进程中作为
$
(renderer.js
文件)提供