0

I want to rotate element(clockwise on downscroll & anti-clockwise on upscroll) while scrolling the page. For that i use javascript code.But it's not working in angular.I just use the CDN links in index.html.Javascript code is not working in angular.Want to rotate starburst in top right corner

Html File:

<div class="starburst discount" id="star">
   <span>17%</span>
 </div>

My Javascript File is:

<script> 
var star = document.getElementById("star");
window.addEventListener("scroll", function() {
star.style.transform = "rotate("+window.pageYOffset+"deg)";
</script>

Is there any other way to achieve the element rotate in Angular?Can anyone help with this?Thanks in Advance..

5
  • I don't need rotating on hover.i want to achieve this when scrolling.Got it? Commented Jul 19, 2018 at 10:33
  • @Arthi which version of angular you are working on? Commented Jul 19, 2018 at 10:35
  • codepen.io/runamuk0/pen/OPNXyV. Just Modify click event to scroll in this sample Commented Jul 19, 2018 at 10:35
  • Angular 6.0.9@Javascript_Lover Commented Jul 19, 2018 at 10:40
  • Its fine.where to include the js code in angular.I just gave the code inside the index.html file.but it does not work @NullPointer Commented Jul 19, 2018 at 10:44

2 Answers 2

2

Here is a working example of how to handle window scroll event in angular: https://stackblitz.com/edit/angular-3z533s. I have used HostListener to bind event handler to window scoll event. Refer: HostListener

Sign up to request clarification or add additional context in comments.

19 Comments

It's working.. But the problem is am displaying multiple products as in the above figure. The first element is alone rotate while scrolling rest of the list doesn't rotate.
How can i achieve this for all starbursts in all products?
U r just amazing..I had been searching for this since morning..Thanks its working..
Happy to help:-)
|
0

You can use angularjs Directive for DOM Manipulation Angular Directive

2 Comments

Am using Angular 6 version
sorry i thought you were talking about angularjs

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.