简体   繁体   English

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

[英]How do I link jQuery with Angular? I want this simply jQuery code to animate all of my20+ divs

Basically trying to animated my 25+ divs (square blocks, regular height width 100px bg-color: blue) but in angular because I have three routes. 基本上是尝试为25个以上的div动画(正方形块,常规高度宽度100px,bg-color:蓝色),但由于我有3条路线,所以设置了角度。 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? 制作一个新的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);
    });
});

To use jQuery, simply ensure it is loaded before the angular.js file. 要使用jQuery,只需确保已在angular.js文件之前加载了它。 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. 您还可以使用ngJq指令来指定应在jQuery上使用jqlite,或者如果页面上存在多个版本,则可以使用特定版本的jQuery。

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. 假设您在关闭body标记之前有对角度控制器的同步脚本引用,则可以执行将其保留在控制器中的操作,但这是不合要求的,并且在不重复代码的情况下不能在其他控制器中重复使用。 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异步加载。

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

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