Image magnifier in Angular
Here is a working stackblitz as per your requirements. It shows the implementation of image zoom functionality mentioned on w3school.
https://stackblitz.com/edit/angular-w3school-image-magnification
You have not shown your html and css files. So, I am not totally sure but the following might be the reason why zoom is not working for you.
Problem is that img-magnifier-glass div element is created using classical DOM method 'document.createElement'. And then, class 'img-magnifier-glass' is applied to it, again using a classical DOM method (setAttribute). But, in angular, styles are encapsulated. So, if you have added a class definition of '.img-magnifier-glass' in app.component.css then that class won't be applied to glass div since it is not mentioned in the template (app.component.html). See this for more info - https://github.com/angular/angular/issues/7845
To fix this, you can either move definition of class '.img-magnifier-glass' to styles.css (Where global styles are defined)
or you can keep the class in app.component.css but use pseudo-selector ::ng-deep with it. Applying the ::ng-deep pseudo-class to any CSS rule completely disables view-encapsulation for that rule. Any style with ::ng-deep applied becomes a global style.
::ng-deep .img-magnifier-glass {
}
or you can stop style encapsulation for component by specifying
@Component({
// ...
encapsulation: ViewEncapsulation.None, //<<<<< this one!
styles: [
// ...
]
})
It will be better will be if you use Renderer2 (https://angular.io/api/core/Renderer2) instead for creating dynamic elements like glass element here. Renderer2 will take care of correctly encapsulating class applied on elements created using it.
Angular 7 Image zoom is not working on mouse hover
- Use [zoomMode]="'click'" to enable zoom on click
- Use [zoomMode]="'hover'" to enable zoom on hover
I've updated the stackblitz - https://stackblitz.com/edit/autocompcus-j5kujt.
Related Topics
Twitter Bootstrap Button Click to Toggle Expand/Collapse Text Section Above Button
How to Make Each Letter in Text a Different Random Color in JavaScript
CSS Overflow Hidden Increases Height of Container
Scrolling Log File (Tail -F) Animation Using JavaScript
How Much of an Effect Can Different Operating Systems Have on Displaying Web Pages
Horizontal Swipe Slider with Jquery and Touch Devices Support
Jquery If Then Statement for CSS Value
Grabbing Style.Display Property via Js Only Works When Set Inline
Dropdown Image Not Visible in Chrome and Ie
JavaScript How to Check User Agent for Mobile/Tablet
Hover Effects on Irregular Polygons in CSS
How to Detect Which CSS Grid Column and Row an Element Is in Using JavaScript
Get Current CSS Property Value During a Transition in JavaScript
Animating Max-Height with Pure Js
How to Trigger the :Active Pseudoclass on Keyboard 'Enter' Press? (Using Only CSS)