开发者

css("Right", posVar); does not work

The Main objective here is to make an instant "jump" to the right. I don't want to use .animate(), because it makes a little "flashing" effect - b开发者_JAVA百科ecause it is not instant. I think .css() will make an instant "jump" to the right, without flashing effect.

I don't know why this will not work.. Instead of using .css() I actually have to workaround this issue with .animate:

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

Here is my actual code:

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

What's wrong with that?

CSS:

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


Css attributes:left, right, top, down will not work with display:block try display:absolute or display:fixed

I dont know what was on my mind when I wrote that answer. I mean to say.... you need position:absolute or position:fixed or position:relative

And I think the problem with your code is there is not "px" at the end...

I have fiddeled it, and here it is http://jsfiddle.net/Starx/8w6cS/

YOUR CODE IS WORKING HERE IS A PROOF

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


AND IF YOU TRYING TO MOVE YOUR ul to 2838px to the right Here is your solution

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


You mean position: absolute or position: fixed. It'll work with display block though.

I tried the following code, and it works:

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


It should work. Here’s a jsFiddle with your example code, working fine: http://jsfiddle.net/mathias/PjQBe/

Please provide us with more code.


Change the CSS as follows:

#gallery ul {
    display:block;
    position:relative;
    right:0px; /*THIS WILL DO THE TRICK FOR JQUERY */
    width:14000px; /*auto calculated from javascript */
}

now your jQuery code will work!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜