css("Right", posVar); is not functioning properly

The main goal here is to achieve an instant "jump" to the right without any flashing effects. Instead of using .animate(), which can cause a flickering effect, I believe that .css() will provide the desired instantaneous movement to the right.

However, for some reason this approach does not seem to work as expected and I have to resort to a workaround using .animate():

$("#gallery ul").animate({right: posVar},0);

Below is the snippet of my current code:

setTimeout(function(){
   var posVar = 2838;        
   $('#gallery ul').css("right", posVar);
}, 300);

What could be causing this issue?

CSS:

#gallery ul {
  display:block;
  position:relative;
  width:14000px; /*auto calculated from javascript */
}

Answer №1

When using display:block, the CSS attributes left, right, top, down will not work. Instead, try using display:absolute or display:fixed.

Apologies for the confusion in my previous answer. You actually need to use position:absolute, position:fixed, or position:relative.

It seems that the issue with your code is missing the "px" at the end...

I have made adjustments and here is the updated fiddle link http://jsfiddle.net/Starx/8w6cS/

YOUR CODE IS WORKING - HERE IS THE PROOF

http://jsfiddle.net/Starx/8w6cS/1/


If you are attempting to move your ul 2838px to the right, here is the solution

http://jsfiddle.net/Starx/8w6cS/2/

Answer №2

Are you referring to using position: absolute or position: fixed? It should still function properly even with a display block.

I experimented with the code below, and it produced the desired outcome:

setTimeout(function(){
    var positionVariable = 100;        
    $('#gallery ul').css({ right: positionVariable + 'px' });
},300);

Answer №3

It appears to be functioning correctly. You can view the working example code in this jsFiddle link: http://jsfiddle.net/mathias/PjQBe/

If you could share additional code, it would be helpful for further assistance.

Answer №4

Modify the CSS in the following way:

#photo-gallery ul {
    display:flex;
    position:absolute;
    left:0px; /*THIS SIMPLE TWEAK WILL HELP WITH ANIMATION */
    width:20000px; /*calculated dynamically using JS */
}

With these tweaks, your jQuery script should function smoothly!

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

Encountering numerous connection issues while utilizing node.js with mongodb

Within my code structure, I have defined a schema in the /routes/schema.js file... var mongoose = require('mongoose'); var Schema = mongoose.Schema; var userSchema = new Schema({ username: String, password: String, name: String, ...

Update the anchor tag's background color when it is clicked and the href attribute is set to

Coding <div id="main_menu"> <ul> <li><a href="#">Homepage</a></li> <li><a href="<?php echo $this->url(array('controller' => 'eftrqsthead','ac ...

Is there a way to collapse just one specific row in Angular?

I am struggling to toggle only the selected row, any suggestions? Take a look at my code and demonstration here: https://stackblitz.com/edit/test-trainin-2-gv9glh?file=src%2Fapp%2Fapp.component.scss Currently, all rows are being toggled when clicked, but ...

jCarouselLite problem: Images refusing to display in jQuery

My website currently has jCarouselLite integrated, but I'm facing an issue where the PREV and NEXT buttons are visible, yet no IMAGES are showing up. The image links seem to be correct. Do you have any suggestions? jQUERY: <script type="text/jav ...

Update the second selection when the first selection is changed

Apologies for not including "my attempt" here, I struggle with jquery and need some guidance!! I want to modify the value of a second selector based on the outcome of the first. In my database, I have a list of builders and regions under the headings bui ...

Is it possible to superimpose a post-type title onto the featured image?

I have crafted this WP_Query to extract the titles and featured images from my post types. <div class="job-cont"> <?php $query = new WP_Query( array( 'post_type' => 'jobs' ) ); if ( $query->have_posts( ...

Converting JSON data into an HTML table

I'm struggling to convert a JSON object into an HTML table, but I can't seem to nail the format. DESIRED TABLE FORMAT: Last Year This Year Future Years 45423 36721 873409 CURRENT TABLE FORMAT: Last Year 45423 This ...

Find a solution to the issue of displaying react icons within JavaScript with embedded objects

When icons are added inside the JavaScript condition, the icon only appears as an object and does not display properly {!signUp ? `${(<FcGoogle />)}` + "Sign in With Google": `${(<FcGoogle />)} Sign Up With Google`} view image descri ...

What is the method to verify if an AJAX request has already been initiated using Jquery?

Currently, I have implemented an Ajax request using Jquery to submit a form. $.ajax( { type: "POST", url: "login.php", data: $("#signin").serialize(), dataType: "json", cache: false, ...

Waiting for a page to fully load using Selenium and JavaScript

After clicking a link, I have to wait for the webpage to finish loading. The title of the new page remains unchanged, but the URL changes from "something.com" to "something.com/abc". Because of this, I am unable to utilize driver.wait(until.titleIs(&apo ...

jasmine and protractor test failing due to use of byID

My HTML markup is all set and valid. While using WebStorm to debug my test cases, I am able to view this specific element without any issues... <a id="privacyPolicy1234" on-tap="goPrivacyPolicy()" class="disable-user-behavior">Privacy Policy</a&g ...

Encountered a connection error while attempting to establish a connection in Node.js

Every time I try to execute the code, I encounter this error message: throw new Error('Most middleware (like ' + name + ') is no longer bundled with express and must be installed separately ^ Error: Most middleware(like BodyParser) is ...

Retrieving AutoComplete values from a SharePoint 2010 List

I'm facing a challenge and need some help. I'm attempting to load a specific SharePoint 2010 REST column into a JQuery-UI AutoComplete "Source". However, I can't seem to figure out how to do so for the 300 items that need to be loaded. While ...

`Exit out of the current tab and navigate back to the parent tab`

Looking to add a link on a webpage that will specifically close the active tab in a browser without affecting other tabs. Upon clicking the close link, the user should receive an alert message prompting them to confirm with two options: "YES" and "NO". If ...

Well-structured JSON output generated from a string

Source Data: Dialogflow Response : id: \"9f912860-e5c6-4e57-934b-8639595b947f-d571b79b\"\nlang: \"en\"\nsession_id: \"3e22f813-79bb-b29a-1def-4c5e4ce4b23b\"\ntimestamp: \" ...

Use Highcharts gauge to display data retrieved after making a $.getJSON request

Struggling to integrate data retrieved from a PHP script into a Highchart gauge graph. The JSON result is correct, but setting it into the gaugeOptions variables is proving challenging. Specifically, I want to display the PHP values in #container-C_2. Set ...

Transforming JavaScript into TypeScript - school project

After researching similar questions and answers, it appears that any valid JavaScript code can also be considered TypeScript? If this is true: const express = require('express'); const bodyParser = require('body-parser'); const ...

Having trouble understanding the odd behavior in IE7. Suddenly seeing a scrollbar appear when hovering

The webpage layout I am currently experiencing issues with can be found at the following link: When viewing this page in ie7 or ie8 Compatibility View mode, a strange horizontal scrollbar appears whenever I hover over one of the menu items. It seems that ...

Ways to update a specific div upon clicking an image

Is there a way to refresh a div using an image click? I have an image with the id 'sellhide' and another div with the id 'sellChart'. Below is the code: <div class="col-xs-12 col-lg-6 col-sm-6 col-md-6 index_table_three" id="sellCha ...

Open in a new tab for enhanced content formatting in Prismic on NextJs

In my Prismic RichText editor, I have included two files (terms and conditions) that I would like to open in a new tab. Unfortunately, Prismic does not offer an option like target _blank for this functionality. I am currently working with NextJs and Tail ...