如何将jQuery链接到Angular?我想要这个简单的jQuery代码来动画我所有的my20 + div

时间:2021-12-04 20:24:13

Basically trying to animated my 25+ divs (square blocks, regular height width 100px bg-color: blue) but in angular because I have three routes. I want my homepage to have the animation. I will figure that out. But for now, I want to link this code below into my angular app. Do I put it in the controller? Make a new script.js file and link it?

基本上试图动画我的25 + divs(方块,常规高度宽度100px bg颜色:蓝色)但角度因为我有三条路线。我希望我的主页有动画。我会弄清楚的。但是现在,我想将下面的代码链接到我的角度应用程序中。我把它放在控制器里吗?制作一个新的script.js文件并链接它?

$(document).ready(function() { 
    $('.blockone').mouseenter(function() {
        $(this).animate({
            height: '+=40px'
        });
    });
    $('div').mouseleave(function() {
        $(this).animate({
            height: '-=40px'
        });
    });
    $('div').click(function() {
        $(this).toggle(200);
    });
});

2 个解决方案

#1


0  

To use jQuery, simply ensure it is loaded before the angular.js file. You can also use the ngJq directive to specify that jqlite should be used over jQuery, or to use a specific version of jQuery if multiple versions exist on the page.

要使用jQuery,只需确保在angular.js文件之前加载它。您还可以使用ngJq指令指定jQueryite应该用于jQuery,或者如果页面上存在多个版本,则使用特定版本的jQuery。

#2


0  

you haven't shared enough code to be able to say exactly whether your solution would work.

您没有共享足够的代码,无法准确说出您的解决方案是否有效。

assuming you have synchronous script references to your angular controller right before the closing body tag, leaving it in your controller may execute but this is frowned upon and cannot be reused in other controllers without repeating the code. you could have this code in a service, and inject it in the controller.

假设您在关闭正文标记之前对角度控制器进行了同步脚本引用,将其保留在控制器中可能会执行,但这是不受欢迎的,不能在不重复代码的情况下在其他控制器中重复使用。您可以在服务中使用此代码,并将其注入控制器中。

if you wanted to load it as a separate file, you could load it asynchronously with jqlite's $http or jQuery $.ajax.

如果你想把它作为一个单独的文件加载,你可以用jqlite的$ http或jQuery $ .ajax异步加载它。

#1


0  

To use jQuery, simply ensure it is loaded before the angular.js file. You can also use the ngJq directive to specify that jqlite should be used over jQuery, or to use a specific version of jQuery if multiple versions exist on the page.

要使用jQuery,只需确保在angular.js文件之前加载它。您还可以使用ngJq指令指定jQueryite应该用于jQuery,或者如果页面上存在多个版本,则使用特定版本的jQuery。

#2


0  

you haven't shared enough code to be able to say exactly whether your solution would work.

您没有共享足够的代码,无法准确说出您的解决方案是否有效。

assuming you have synchronous script references to your angular controller right before the closing body tag, leaving it in your controller may execute but this is frowned upon and cannot be reused in other controllers without repeating the code. you could have this code in a service, and inject it in the controller.

假设您在关闭正文标记之前对角度控制器进行了同步脚本引用,将其保留在控制器中可能会执行,但这是不受欢迎的,不能在不重复代码的情况下在其他控制器中重复使用。您可以在服务中使用此代码,并将其注入控制器中。

if you wanted to load it as a separate file, you could load it asynchronously with jqlite's $http or jQuery $.ajax.

如果你想把它作为一个单独的文件加载,你可以用jqlite的$ http或jQuery $ .ajax异步加载它。