2

I need to add an ng-click function on image, when I click on it is must increase size and after when I left the mouse over come back to original size.

with css i have create this and run good when put mouse on image

 .images img{
  float: left;
  height: 100px;
  width: 100px;
}

.images img:hover{
width: 30%;
height: 30%%;
transition: width 2s, height 4s
}

on the html i have

 <img ng-click="$ctrl.changeSize(img)" ng-src="https://www.google.it/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png"  />

i don't know what i must write on changeSize for change the size of image when i click on it.

I'd like to use ng-click event, how can call into function changeSize the css values ?

thanks.

4
  • did you try ng-class with a flag changing on click? Commented Nov 24, 2016 at 14:51
  • You can as well use query style with angular.element(document).find('the element name').css({ 'width': '30%', 'height': '30%' }); this will be from your controller after triggering the function with ng-click Commented Nov 24, 2016 at 14:53
  • @ Vali how can use a flag on click into ng-class ? Commented Nov 24, 2016 at 14:58
  • @akinjide I'd like use values from .css and not put value of changing directly into .js Commented Nov 24, 2016 at 14:59

2 Answers 2

0

The function needs to be in your controller.

function toggleSize() {
  angular.element(document).find('#img-responsive').css({ 'width': '30%', 'height': '30%' });
}

<img id="img-responsive" ng-click="$scope.toggleSize()" ng-src="https://www.google.it/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png"  />
Sign up to request clarification or add additional context in comments.

1 Comment

thanks for this solution but i can't change the values from .css, every changing must be done into js. I'd like modify values from .css
0
 <img ng-click="$ctrl.toggleSize()" ng-class="{little: $ctrl.littleSize, big: !$ctrl.littleSize}" ng-src="https://www.google.it/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png"  />

And in your controller :

$ctrl.littleSize = true;

$ctrl.toggleSize = function() {
    $ctrl.littleSize = !$ctrl.littleSize;
}

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.