与jQuery整合angularJS [英] Integrating angularJS with JQuery

查看:123
本文介绍了与jQuery整合angularJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新为angularJS和jQuery。我想preVIEW的图像时,我的鼠标移动到某个环节。 previewing图像的功能是从 http://cssglobe.com/lab/tool​​tip /03/main.js 。和预期的演示也是:
http://cssglobe.com/lab/tool​​tip/03/

I am new for both angularJS and Jquery. I would like to preview an image when my mouse moves to some link. The function of previewing image is from http://cssglobe.com/lab/tooltip/03/main.js. And the expected demo is also: http://cssglobe.com/lab/tooltip/03/

下面是我的code:

的index.html

"index.html"

<!DOCTYPE html>
<html>
<head>
  <script src="jquery.js" type="text/javascript"></script>
  <script>
    this.screenshotPreview = function(){
    xOffset = 10;
    yOffset = 30;
    // these 2 variable determine popup's distance from the cursor
    // you might want to adjust to get the right result
    $("a.screenshot").hover(function(e){
        this.t = this.title;
        this.alt = "";
        var c = (this.t != "") ? "<br/>" + this.t : "";
        $("body").append("<p id='screenshot'>
        <img src='"+ this.rel +"' alt='url preview' />"+ this.t +"</p>");
        $("#screenshot")
          .css("top",(e.pageY - xOffset) + "px")
          .css("left",(e.pageX + yOffset) + "px")
          .fadeIn("fast");
      },
      function(){
        this.title = this.t;
        $("#screenshot").remove();
      });
      $("a.screenshot").mousemove(function(e){
      $("#screenshot")
        .css("top",(e.pageY - xOffset) + "px")
        .css("left",(e.pageX + yOffset) + "px");
      });
   };
   // starting the script on page load
   $(document).ready(function(){
    screenshotPreview();
  });
 </script>
 <style>
   #screenshot{
     position:absolute;
     border:1px solid #ccc;
     background:#333;
     padding:5px;
     display:none;
     color:#fff;
    }
  </style>
 </head>
 <body ng-app="app"  ng-controller="Ctrl">
  <li ng-repeat="image in images" style="color:#000000;">
   <a href="#/image"  class="screenshot" 
      ng-mousemove="$parent.selectedImage= image.id"
      rel= "{{getImage()}}" >
         {{image.name}}</a>
 </li>
 </body>
</html>

app.js的code是:

The code of app.js is:

  angular.module('app')
    .controller('Ctrl', function ($scope) {
      $scope.selectedImage= '';
      $scope.images= [
        {id : 1, name : 'image1'},
        {id : 2, name : 'image2'},
        {id : 3, name : 'image3'}
       ];

         $scope.getImage = function (){
            if (!angular.equals($scope.selectedImage, '')){
              return 'image.png';
         }
    };
 });

它不工作里面NG-重复,但没有NG重复工作正常。

It doesn't work inside ng-repeat, but works fine without ng-repeat.

感谢

推荐答案

您可以自定义的指令,并调用链接函数内部jQuery插件

you can make custom directive and call your jquery plugin inside link function

  var directiveModule = angular.module("directiveModule", []);

    directiveModule.directive('wrapJqueryplugin', function() {
        return {
            restrict : 'E',
            link : function(scope, element, attrs) {        
    *********your jquery code ****************
});

和在你看来

    <wrap-jqueryplugin>
***    any Dom Elements ***
    </wrap-jqueryplugin>

这篇关于与jQuery整合angularJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆