Tips for shifting a div to the left with AngularJS

I am working with a div structure that looks like the following:

<div class="col-xs-1 scroll-button"><i class="glyphicon glyphicon-chevron-left"></i> </div>
<div class="customer-ust-bant col-xs-22" id="letters">
    <box ng-repeat="lt in alph" name="{{lt}}" id="{{lt}}"></box>
</div>
<div class="col-xs-1 scroll-button" ng-click="gotoBottom()"><i class="glyphicon glyphicon-chevron-right"></i> </div>

Also, here is the template for the box:

<div class="alphabet-kutu">{{name|uppercase}}</div>

And the corresponding directive:

app.directive("box", function() {
return {
    restrict:"E",
    scope:{
        name:"@"
    },
    templateUrl:"/static/templates/customers/box.html",
    link:function(scope,elem,attrs,ctrl) {

    }
  };
})

My goal is to display letters of the alphabet inside a horizontal scrolling div.

However, I'm facing an issue when trying to scroll this div to the left upon button click.

 $scope.gotoBottom = function (){
var element = angular.element( document.querySelector( '#letters' ) );
    element.animate({scrollLeft: element.offset().left}, "slow");
    //element.scrollLeft(100);

};

I have attempted using animate and scrollLeft functions but with no success. Is there any AngularJS-specific method that can help me achieve this? How can I effectively scroll a div to the left using jQuery?

Answer №1

Perhaps considering a different value for scrollLeft would be beneficial in this scenario. The current code attempts to scroll the element to its already existing location, resulting in no movement. An alternative approach could be:


element.animate({scrollLeft: element.offset().left - 50}, "slow");

Reminder: jQuery must be included for this functionality to work correctly. The limited version of jQuery within angularJS may not fully support the animate function.

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

The AngularJS $HTTP loop counter fails to update

When working with an HTTP service and binding JSON data to HTML, I implemented the following code: This function uses a 2-second timer to automatically fetch data whenever there is a change in the backend. function sampleDevices ...

Hover over the image to reveal sliding text

I am attempting to incorporate a CSS3 hover effect into my images, where hovering over an image will cause some text to slide up on a white background. However, I have encountered issues with conflicting code, as I also have overlay text and a 'new&ap ...

Guide on showcasing the values from two text fields with autocomplete suggestions in a third text field

Hey there, I have a search form that takes values from two text fields and combines them to populate a third text field for querying. <form name="form1" method="post" action="" autocomplete="off" oninput="sea.value = password.value +''+ passw ...

How can JS be used to create content without refreshing the page?

On my website, I have a staff directory where each individual can be selected by clicking on their profile. When a staff member is clicked, a jQuery mobile popup opens and loads dynamic content using AJAX. Within this popup, users have the option to delete ...

How come my keyframes animation isn't functioning properly on my div element?

I am currently designing a custom animation for a checkers game. My goal is to create an effect where the checker piece moves slowly to its next spot on the board. Below is the CSS code I have used: @keyframes animateCheckerPiece { 0% {top: ...

Can the JavaScript code be altered within the client's browser?

So, I'm using JQuery Validator on my webform to validate form data. However, I haven't added any validation on the server side. I'm curious if it's possible for a user to modify the code and bypass my validations in their browser. If th ...

Customize Tab indicator styling in Material-UI

Currently, I am attempting to customize the MUI tab by changing the indicator from a line to a background color. Through my research, I discovered that using TabIndicatorProps and setting a style of display:none eliminates the indicator completely. However ...

What could be the reason my view is not rendering after calling my action through Ajax?

I am encountering an issue with my Ajax call that is hitting the controller action 'SearchFromWithin'. The problem I am facing is that the view does not get displayed when the call is made. Although I can enter the view and step through it, the s ...

I am unable to directly access the route using the browser's URL. Is there an alternative solution

When using $locationProvider.html5Mode(true) in AngularJS, I am unable to route directly by typing the URL in the browser. Here is a snippet from AppRouting.js: myApp.config(['$routeProvider', function($routeProvider) { $locationProvider.html ...

Extracting data on an AngularJS platform by using web scraping techniques

I have been working on an AngularJS application that currently retrieves JSON data from an API using http.get, and it's been working really well. Recently, I've been exploring the idea of passing a URL to a static webpage and scraping the result ...

Obtaining the Immediate ID of a Widget using JQuery

I currently have the following setup: <div id="dualList"></div> I created a plugin but stripped it down for testing purposes. I am encountering difficulties with the plugin not displaying the ID of the div. <script> (function($) { ...

Close button for body

I have created a form that floats in the center of the screen On this form, I have included a button designed to close it However, I would like for the form to be closed anywhere on the screen when clicked with the mouse Here is my code: $(".offer-clo ...

Skip ahead button for fast forwarding html5 video

One of the features in my video player is a skip button that allows users to jump to the end of the video. Below is the HTML code for the video player: <video id="video1" style="height: 100%" class="video-js vjs-default-skin" controls muted autoplay=" ...

What is the best way to input a dynamic post array in PHP?

Explaining this might be challenging, but I will do my best. I have multiple input posts with custom conditions, which means there can be as many custom conditions as needed. Here is the HTML: <input name="type[]" value="type 1"> <input nam ...

Dynamically loading AngularJs controllers with the help of ui-router and requireJs is a

I have seen various articles online discussing how to dynamically load AngularJS controllers, but I am interested in loading controllers and templates using UI router and RequireJS. How can I achieve this? ...

Leveraging the power of PHP variables within jQuery code

Wondering how to incorporate a PHP value into jQuery? My approach involves retrieving the VAT rate from the database using PHP and storing it in $vatrate: $sqlv = <<<SQL SELECT * FROM `vatrate` WHERE id='1' SQL; if(!$resultv = $db-&g ...

Changing the value of $i within a form

One of my web forms has 10 lines by default with checkboxes and textboxes. The code looks like this: <form method="post" action="actionhere"> <?php for($i=0; $i<10;$i++) { ?> <div class='clone_me'> <span> ...

Replace anchor text using jQuery

I'm currently working on implementing a like system, but I've encountered an issue. When a user clicks the like button, the text should change from "Like" to "Remove Like". The data is being fetched from a PHP query, so there are multiple items ...

Analog Clock Time Adjustment Bubble Deviation Dilemma

Recently, I encountered an issue with an analog clock component. Every time I click on the time adjustment bubble repeatedly while also moving the cursor position, it tends to drift away from its original placement, which should ideally be between an orang ...

How can I make a basic alert box close after the initial click?

After clicking a button, I have a simple jQuery script that triggers a fancybox. However, the issue is that the fancy box does not close after the first click of the button; it only closes after the second click... Another problem arises inside the fancy ...