2014-02-19 78 views
1

這是我的代碼:角:jQuery的動畫不工作

app.directive('help', function() { 
    return { 
    restrict: 'A',    
    link: function (scope, elem, attrs) { 

     elem.bind('click', function() { 
     var mainContent = $('#main-content'); 
     mainContent.animate({ 
      "margin-left": '350px', 
      "margin-right": '0px', 
     }, 1000, function() {}); 
     }); 
    } 
    } 
}); 

我是新手的角度,以及動畫不起作用。 我做錯了什麼?

+0

任何錯誤?你可以在jsfiddle或plunker中重現嗎? – shaunhusain

回答

1

我只是複製你的代碼,增加了jQuery和角度,似乎工作:在控制檯

http://plnkr.co/edit/i4B8bVbWrei4Ly74Ik2r

// Code goes here 

angular.module("myApp",[]).directive('help', function() { 
    return { 
    restrict: 'A',    
    link: function (scope, elem, attrs) { 
     elem.bind('click', function() { 
     debugger 
     var mainContent = $('#main-content'); 
     mainContent.animate({ 
      "margin-left": '350px', 
      "margin-right": '0px', 
     }, 1000, function() {}); 
     }); 
    } 
    } 
}); 

的HTML

<!DOCTYPE html> 
<html> 

    <head> 
    <script data-require="[email protected]*" data-semver="2.0.3" src="http://code.jquery.com/jquery-2.0.3.min.js"></script> 
    <script data-require="[email protected]*" data-semver="1.2.13" src="http://code.angularjs.org/1.2.13/angular.js"></script> 
    <link rel="stylesheet" href="style.css" /> 
    <script src="script.js"></script> 
    </head> 

    <body ng-app="myApp"> 
    <h1 help="" id="main-content">Hello Plunker!</h1> 
    </body> 

</html>