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

Error: Failed to Locate WebMethod Ajax Call

I am in the process of developing a web form that will trigger an email notification upon submission. I have written a webmethod and attempting to use ajax for posting. However, I am encountering a 404 error when I try to submit the form. Below is the co ...

Retrieve the initial data of the AngularJS model upon button click

Previously, I was able to retrieve the initial values of the model using this.model.changed or this.model._previousAttributes in BackboneJS. Now, I am looking to achieve the same functionality in AngularJS, where I can track all changes made to the model ...

Unforeseen Issues Arising from Media Queries

Trying out some new styling for different screen sizes based on the bootstrap grid system dimensions. Facing an issue where only certain styles apply while others don't seem to take effect. Here's a snippet of the CSS: @media only screen and ( ...

What is the best way to implement a form sliding into a new page with ajax?

I am looking to implement a sliding form feature on my main page in response to a button click. Currently, my project is utilizing asp.net razor pages. Here's the scenario: when the highlighted button is clicked A div containing a form should slide ...

Setting up a Bootstrap tokenfield for usage with a textarea

I was attempting to set up a tokenfield on a textarea with increased height, but it is showing up as a single-line textbox. How can I modify the tokenfield to function properly with a textarea? <textarea name="f1_email" placeholder="Enter Friends' ...

The dropdown menu button stubbornly remains open and refuses to close

Having an issue with a dropdown menu button where it should open when clicked on the icon and close when clicking off the icon or on the icon again, but instead, it remains open. Here is a screenshot for reference: https://i.stack.imgur.com/UX328.jpg I&a ...

Update the browser URL dynamically without redirecting the page, by utilizing JavaScript after an AJAX call receives a

I am currently endeavoring to find a solution to replace the URL on my page without triggering a reload. My approach involves utilizing an infinite scroll JavaScript plugin. Upon receiving a response from an AJAX call, I intend to update the URL with the n ...

What is the best way to merge two arrays into one single array using jQuery?

After selecting values from 2 different arrays obtained from checkboxes, my goal is to combine those values into a new array. The desired outcome would be an array with the following elements: [3,5,6,9] Let's assume that I have already initialized th ...

Update the content of the h5 tag dynamically as the new div's data attribute is revealed by scrolling into view

I would like to dynamically update the h5 tag text based on the data attribute of the current div when it comes into view. The CSS is configured so that each .bar class div occupies 100% height, with only one visible at a time. I have successfully implemen ...

Filter your DataTables columns by searching for text within a specific range

Below is the code for implementing a text range filter in SQL: function fnCreateTextRangeInput(oTable) { //var currentFilter = oTable.fnSettings().aoPreSearchCols[i].sSearch; th.html(_fnRangeLabelPart(0)); var sFromId = oTable. ...

Tips for enabling multiple v-list-group components to remain open simultaneously (bypassing the default Vue behavior)

Currently, I am facing an issue with Vue's default behavior where only one v-list-group can be open at a time. I am using Vuetify 2.6 and have attempted to use the multiple prop without success. Additionally, individually assigning the :value prop to ...

Tips for concealing the sorting number in the grid header

I have implemented angularjs ui-grid for sorting 4 columns in my grid. However, I want to hide the sort numbers displayed in the grid. I have searched for a solution or configuration through API but did not find anything helpful. Thank you. https://i.sta ...

New to CSS/Ruby - What causes two adjacent buttons to have varying sizes?

The varying sizes of my search and login buttons located beside each other are puzzling me. Could it be due to the fact that the search button is enclosed within a submit_tag argument while the login button is not? If this is indeed the case, how can I mak ...

Using a directive attribute will convert a boolean value to a string

Is it possible to pass a boolean value to my directive without isolating its scope? The directive includes a link function that captures the attribute's value: link: function(scope, element, attrs, ctrl) { scope.myAttributeValue = attrs.myAttri ...

Managing JSON communications in Scala Play Framework and forwarding them to AngularJS JavaScript

Working on the implementation of a library system using Play Framework and AngularJS. To search for a book in the library, the user enters a keyword value in the input field. This value is received by the controller from a GET request. The task is to searc ...

Switch the checkbox to a selection option

Is there a way to switch the selection method from checkboxes to a dropdown menu? $("input[name=koleso]:first").prop("checked", true); $('body').on('click', '.koleso label', function (e) { koles ...

Testing an ngTagsInput element with Protractor: A step-by-step guide

I am currently facing an issue with testing a simple form using Protractor. The form works fine with basic input types, but I am encountering difficulties with ngTagsInput integration. I am looking for a way to set it up correctly without triggering the er ...

Set the cookie to expire in 5 minutes using PHP, JavaScript, or jQuery

Is there a way to set a cookie in PHP that expires in 5 minutes? I am comfortable with the setcookie() function, but unsure about how to set the expiration time. Any explanation would be greatly appreciated. Could someone please guide me on how to achieve ...

How to position and center a div layer over another div

I have been struggling to place a div over another div that contains an image. The div needs to have a simple HTML link just like the example shown in this picture: However, when the page loads, the URL is not centered on the image as you can see on the l ...

What steps should I take to resolve the textarea border bottom CSS effect?

My simple border bottom animation is working fine with a basic input element, but it's not functioning properly when used with a textarea. (If using JavaScript is necessary for a solution, please provide guidance) How can I adjust the height of a te ...