Create a dynamic scrolling animation for overflowing text in Angular 8

Currently, I am developing an Angular 8 application and looking for a way to handle text-overflow only when there is excess text that doesn't fit the screen. Specifically, I would like the text to scroll from right to left in such cases. I do not want any animations if the text fits within the screen. While it might be easy to achieve this using Jquery or other libraries, due to my project constraints in Angular 8, I am seeking a pure CSS solution or a TypeScript alternative. You can check out my progress so far by following the link provided below. Currently, on hover, everything animates, but I am looking to animate only the first paragraph and leave the second one as is.

https://stackblitz.com/edit/angular-inifat

Answer №1

Hopefully, this meets your expectations. Let's give it a try and provide feedback.

app.component.css

.text { 
  overflow: hidden;
}
p {
  text-align: center;
  white-space: pre;
  transition: 30s;
} 

app.component.html

<div class="text"  #parentTag (mouseenter)="move()" (mouseleave)="stop()">
  <p #target  >This is some long long super long, extremely long text right here This is some long long super long, extremely long text right hereThis is some long long super long, extremely long text right here This is some long long super long, extremely long text right here This is some long long super long, extremely long text right here This is some long long super long, extremely long text right here This is some long long super long, extremely long text right here
</p>
<div> 

app.component.ts

import { Component, ElementRef,Renderer, ViewChild, Renderer2 } from '@angular/core';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ]
})
export class AppComponent  {
  name = 'Angular';
  left = 0;
  @ViewChild('parentTag', {static: false})
  parentTag: ElementRef; 

  @ViewChild('target', {static: false})
  target: ElementRef;

  constructor(private el:ElementRef, private renderer: Renderer2){

  } 

  move(){
    console.log(this.parentTag.nativeElement.clientWidth); 
    console.log(this.target.nativeElement.scrollWidth);
    let left = this.target.nativeElement.scrollWidth - 
    this.parentTag.nativeElement.clientWidth; 
    this.renderer.setStyle(this.target.nativeElement, 'margin-left', '-'+left+'px');
  }

  stop(){
    this.renderer.setStyle(this.target.nativeElement, 'margin-left', '0px');
  }

}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Troubleshooting problems with Z-Index div hover overlay on [windows] and Webkit browsers (Safari, Opera, etc)

Note: This issue is specific to Windows Webkit and does not affect Macs I am attempting to create a grid with fixed-size cells containing background images. When hovered over, the background image changes and the cell's height increases, overlaying t ...

Phonegap Application: Page design gets distorted following keyboard input

After a user enters login details and the next page loads, the layout shifts as shown in the image below. The entire app layout breaks and the view moves down to accommodate the size of the onscreen keyboard. This issue persists unless the orientation is ...

Setting a condition for a function call when a checkbox is clicked

My table has columns labeled NoBill and Bill, with checkboxes as the values. Here is the default view of the table: https://i.stack.imgur.com/ZUvb2.png When the checkbox in the NoBill column is clicked, the total value (this.total) is calculated. The t ...

Enhance JQM Styled Element with an Extra Class Using JQuery Mobile

My goal is to include a class in JQM's list divider <li>'s: <li data-role="list-divider" role="heading" class="ui-li ui-li-divider ui-bar-e ui-first-child">A</li> I have attempted to accomplish this by utilizing JQuery within ...

Hiding the visibility of a table-cell will conceal the background color of its parent table row

In my coding project, I have implemented forms with a structure that utilizes display:table-row and display: table-cell. Previously, in Firefox 52, I was able to hide a cell element using visibility:hidden, effectively hiding the cell while maintaining the ...

Enhance the aesthetics of placeholder text in Semantic UI React using CSS styling

Currently, I am utilizing Semantic UI dropdowns within my React application to generate drop-down menus similar to the ones showcased in their documentation found here: The initial text displayed is "Select Friend", and it appears with a semi-transparent ...

How can I eliminate the scrollbar from appearing on all browsers when visiting my website?

I've encountered an issue while building my portfolio with React.js. I'm having trouble removing the scrollbar. I've attempted using overflow: hidden for the parent element and overflow: scroll for the child div, but it's not producing ...

Two media queries are combining the same declaration, with one targeting iPads and the other targeting desktop devices

In my code, I am utilizing two media queries within a bulleted list li tag. The issue arises when both queries, clearing every nth-child(2n+1) and nth-child(3n+1), are active on the same page in Chrome's device views. This causes the grid layout to ap ...

Trouble setting href in Angular 4 while using an nginx server

Please bear with me as this question is quite lengthy and I'm facing a serious issue. Objective: I need to run my SSL-configured build on a Linux-based server using Nginx, and I want to access it through my domain with the resources located at /ggm ...

Choosing between map and switchMap in RxJS can impact the outcome of

I've been diving into the documentation for both switchMap and map, but I'm struggling to grasp the distinction between the two. Can someone please explain any scenarios where their usage is interchangeable? ...

Text animation that rises smoothly within a concealed overflow region

I'm currently trying to replicate the effect seen in this example: Specifically, I am referring to the text that reads "CREATIVE AGENCY FOR DARING BRANDS" Although it appears simple, I am having trouble figuring out how to achieve it. I primarily wo ...

Click a button to dynamically create a div element with jQuery

Whenever I click the button to add an address, I want to dynamically create a new div structure using jQuery <div id="container"> <div class="address"> <div class="input-reg rb-item input-group"> <sp ...

Expand the <div> to match the complete height of its containing <div> element

There are multiple div blocks within a parent block: one for the menu on the left, and one for the text on the right. How can you make the right inner block stretch to the full height of the parent block like the left one? The parent block has a minimum he ...

position a div within WooCommerce and set it to a fixed position

Beginner in the world of CSS. /// Currently experiencing challenges with one of my web pages. Struggling to properly position the display of the price. Experimented with both absolute and clear attributes. The CSS works fine at a width of 1920px *Guy ...

Having trouble loading my Twitter feed

Having trouble displaying the Twitter timeline in my web browser. Even though I'm using the original code from the Twitter publish website, it's not showing up properly. Initially, the timeline appeared correctly but after refreshing the site wit ...

CSS background: seeking a fresh background for the rest of my pages

When I use CSS background: url(stuffhere.jpeg) for the background, it remains unchanged when clicking on other videos categorized as "projects," not pages. I have attempted using <body id="home"> and <body id="projects">, creating two backgrou ...

Endlessly tapping through each tab with no direction

I am attempting to click on all unopened tabs (elements) randomly across this page. While the code below usually does the trick, it sometimes doesn't click on all elements. I suspect that there might be an issue with how it loads indexes or some othe ...

Unable to manually adjust the npm configuration file

I encountered an error message while attempting to create a new Angular project using Angular CLI. ng new <project-name> npm WARN registry Unexpected warning for http://registry.npmjs.org/: Miscellaneous Warning ECONNRESET: request to http://registr ...

The HTTP DELETE request encountered a TypeError, stating that error.json is not a valid function

Within my Angular application, there is a feature that involves a "delete button". When this button is clicked, a confirmation popup appears asking the user if they are certain they want to proceed with the deletion. If the user confirms by clicking ' ...

Delayed hover dropdown navigation menu powered by Bootstrap

I am experimenting with creating a bootstrap dropdown menu that opens and closes on hover, but only after a 250ms delay for desktop devices. Custom JavaScript: $(document).ready(function() { if ($(window).width() > 767) { $(".dropdown-toggl ...