Using jQuery Mobile to animate the header text scrolling

I am currently working on the mobile version of a website and I need to incorporate a scrolling functionality for text that exceeds a certain length in pixels. I have been attempting to integrate the following logic into my project:

Here is the source of the scrolling example

I want to implement the same in my example. So far, I have not been successful in making it work. The basic structure will remain the same; I just want the text to scroll if the screen is small in order to display the complete title.

$("div.aaa h2").each(function(){    
  var m = $(this).width();
  var n = $(this).find("div.aaa h2").width();
  var o = m - n;
  var z = $(this).find("div.aaa h2");

    $(this).mouseenter(function(){
        //alert ("title: " + m + " text: " + n + " diff: " + o);
        if (n > m) {
             z.animate({
             left: o                    
         }, 2000);
       }
    }).mouseleave(function(){
            z.animate({
            left: "0"
         }, 2000);    
    });        

}); 

I am open to any solution that works and can detect whether the complete title is visible or not so that scrolling is only implemented for elements with long titles, not all elements.

Another approach I tried was unsuccessful as it scrolled all elements instead of just the one I hovered over:

Check out this alternative method I attempted

Answer №1

Implemented a new parameter called "elem" in the animateTitle function, which is defined after the hover event completes. Removed the width:330px CSS rule from the .aaa class and added additional control for the width of elements with the .aaa class when they are being hovered over.

If you need more information, check out this solution: jsfiddle.net/yVtVe/22/

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

Tips on altering the color of a circle's radius within Google Maps

I'm trying to add a circular radius on a Google Map. Even after reviewing the Google Maps API documentation, I'm still unsure of how to accomplish this task. Below is the code snippet I have been working with: const MyMapComponent = compose( ...

Change the $index value during every iteration within ng-repeat

After each iteration of ng-repeat in angularjs, I need to increment the $index value. I attempted to do so using ng-init in this way, but unfortunately it didn't work as expected and incremented at the start of the ng-repeat loop. Can someone provide ...

JavaScript often struggles to properly read array elements that will occur in the

I am trying to create a navigation system using a JSON-file in the #left div-box. The goal is to have links to the previous and next pages based on the file hierarchy displayed in the #right div-box. However, I am encountering some strange behavior with m ...

An array containing concatenated values should be transferred to the children of the corresponding value

Consider this example with an array: "items": [ { "value": "10", "label": "LIMEIRA", "children": [] }, { "value": "10-3", "label": "RECEBIMENTO", ...

What is the method to retrieve data in Vue when utilizing arrow functions?

When utilizing Vue and arrow functions in methods, we encounter the issue that arrow functions do not have a this keyword. The question then arises of how to access data properties such as list or object. export default { data() { return { list ...

Aligning labels vertically with inputs

How can I align all my input fields (image) to the same vertical line? I tried using the vertical-align css property and a sass mixin I found (see below), but neither seemed to work. @mixin vertical-align($pos) { position: $pos; top: 50%; -we ...

Loading Java Script files in real-time

Is there a method to dynamically load JS files before "$(document).ready" is triggered, while still having them available in the ready event handler? Is there a feature in jQuery that allows for this process? The challenge I am facing involves loading di ...

Break down the execution process of the intricate JavaScript return statement

I am struggling to understand the execution flow of this return statement. If someone could clarify how it works and perhaps discuss the advantages and disadvantages of using such a complex statement instead of a more readable multi-line statement, I wou ...

Stop the occurrence of numerous ajax requests being triggered by clicking

Having an issue with handling multiple ajax requests. In my scenario, there is a form with a button that triggers a service upon clicking it. This service is responsible for loading a list of items into a table, but currently it only loads one item at a ti ...

What is the best method for retrieving options based on a data attribute?

All <option> elements in a <select> have data-value attributes set (example provided below). Upon page load, I must find and iterate through the values of all <option> elements to pick out one that suits further processing. We plan on us ...

Merge and filter unidentified subsets of objects within an array comprised of multiple objects

a more efficient way to achieve the desired output of this code snippet is by checking if sub array 0 exists, combining it, and then filtering the result based on the key code. Your assistance is greatly appreciated! let array = [ { id: 1, te ...

The functionality of serializing jQuery cannot be applied to an input type

I'm trying to utilize the serialize method in Ajax to send form data, but I've noticed that input type text and email are serialized in an array while input type file is not. Here's the form code: <form role="form" action="javascript:;" ...

Sending both a standard jQuery array and a multidimensional array through AJAX to PHP

Currently, I am utilizing AJAX to perform calculations as individuals populate a form. One challenge I am encountering involves passing two different types of arrays through AJAX and manipulating them in PHP. The first array consists solely of ID's, w ...

What is the best way to align bullet points in CSS lists?

These bullet points in my list are not aligned properly, and I am looking for a way to make them even. I remember finding a solution before, but I can’t seem to locate it now. Any assistance would be greatly appreciated. ...

Discovering an item using two different text inputs

I am attempting to retrieve the HTML element object that contains two specific strings. Below is an example with two divs, each named case. I want to access the object based on the content of the p tags inside them: <div class="case"> <p> ...

Tips for eliminating the default arrow on the HTML select tag?

I am currently utilizing vuejs along with tailwindcss and I am trying to figure out how to get rid of the default arrow from an HTML select element. Despite my attempts to remove it by using CSS properties like -moz-appearance, -webkit-appearance, -ms-appe ...

What is the range of possibilities for the response from a jQuery AJAX request?

Currently, my AJAX request is sending data to a page using POST and returning the following: echo '<tr>'; echo '<td>'; echo $product1; echo '</td>'; echo '&l ...

Various results can be produced based on the .load() and .resize() or .scroll() functions despite using the same calculation methods

I'm currently working on developing my own custom lightbox script, but I've hit a roadblock. For centering the wrapper div, I've utilized position: absolute and specified top / left positions by performing calculations... top: _center_ver ...

Record numerous button clicks in the database

Currently, I am developing a web application designed for parents to care for their newborns. Within the app, there are three buttons allocated for each task forming a progress flow, which indicates the completion status of each task (for example, steps fo ...

Deactivate the button when the control validation is triggered within an ng-repeat directive in AngularJS

Code Snippet Link: View Code <form name="myForm"> <div ng-repeat ="ndc in NDCarray"> <div class="col-sm-4 type7" style="font-size:14px;"> <div style="margin-bottom:5px;">NDC9</div> <label>Number: ...