Rotate an ionicon on the page
Asked Answered
D

4

10

I want to display directions with an arrow and was thinking to use the standard ionic arrow for the direction. Can I rotate the up arrow into any direction somehow?

ion-arrow-up-a

Here is an attempt from the comments below

<i class="icon ion-arrow-up-a" rotate degrees="90"></i>


angular.module('app.customDirectives', []).directive('rotate', function() {
      return {
            link: function(scope, element, attrs) {
                // watch the degrees attribute, and update the UI when it changes
                scope.$watch(attrs.degrees, function(rotateDegrees) {
//                  console.log(rotateDegrees);
                    //transform the css to rotate based on the new rotateDegrees
                    element.css({
                        '-moz-transform': 'rotate(' + rotateDegrees + 'deg)',
                        '-webkit-transform': 'rotate(' + rotateDegrees + 'deg)',
                        '-o-transform': 'rotate(' + rotateDegrees + 'deg)',
                        '-ms-transform': 'rotate(' + rotateDegrees + 'deg)'
                    });
                });
            }
    }
});
Dominick answered 16/6, 2015 at 0:57 Comment(2)
Have you looked into the jquery-rotate plugin?Greatgranduncle
I am in the ionic sphere here, so no jquery ( I guess, as I understand jQ is not fully supported / compatible there...)Dominick
K
14

Similar to above, this is how I did it...

HTML:

<i class="ion-arrow-up-c rotate-90">

CSS:

.rotate-90 {
  display: inline-block; 
  transform: rotate(90deg);
}
Kenya answered 4/1, 2016 at 18:7 Comment(0)
E
8

For Ionic icons v1, v2 specifically, the rotate property works only with the display property set to "inline" or "inline-block", it might work with other variations of inline as well.

Then you can rotate them normally using CSS

transform: rotate(90deg);
Enrollment answered 20/3, 2018 at 7:35 Comment(0)
B
6

There is other variants of arrow:

ion-arrow-up-a
ion-arrow-right-a
ion-arrow-down-a
ion-arrow-left-a

Or... As I know, ionic framework is HTML5 based, so you can use CSS styles.

.style {
    -moz-transform: rotate(15deg);
    -webkit-transform: rotate(15deg);
    -o-transform: rotate(15deg);
    -ms-transform: rotate(15deg);
    transform: rotate(15deg);
}

If you want dynamic rotation, you have to check this url.

Busiek answered 16/6, 2015 at 1:2 Comment(5)
Great link! I understand the directive, but it does not rotate my ion-arrow .... I need it to display degrees like in a compass.Dominick
@ElDude Show your code and I will try to figure out whats wrong.Busiek
See code above, basically same from the link you provided.Dominick
@ElDude You can find answer to your question in the same place, where u took this code (link above). You have to create $scope var and pass it to degrees, not just value.Busiek
Thanks, I'll try. But why should it not take hardcoded values?Dominick
A
0

for some reason the <i> element has to own display: inline-block css style to rotate successfully:

controller code:

$scope.angle = 90

HTML:

<i class="ion-arrow-up-c" style="display: inline-block; transform: rotate({{angle}}deg);"></i>
Allophone answered 4/12, 2015 at 5:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.