English 中文(简体)
jj 左右的动动运动
原标题:jQuery animate movement left and right

使用 jquery s . css () i 正在更改左属性值以移动 div 左或右。 我正寻找一种方式在变化发生时对变化进行动画。 没有试过任何效果, 试过 jQueryUI s .show( slide) 函数, 但这会移动整个 div, 而不是所需的 120 px 移动 。

这是我目前没有动画的函数:

$( #plrt ).live("click",function(){
    var lm=$( .plwid ).css("left");
    lm = (parseInt(lm) + 120);
    $( .plwid ).css("left", lm);    
});

这是幻灯片函数, 它没有正常工作, 因为整个 div 是从 display: hide display:show , 而不是简单地移动像素变化

最佳回答

尝试 animate () ()

$( #plrt ).on("click",function(){
    $( .plwid ).animate({ left:  +=120  }, 400 );
});
问题回答

I have whipped up a quick example of what I think you are trying to achieve.
You should check out jQuery Animate.

//note live is deprecated
$( #plrt ).on("click", function() {
  //perform custom animation to add 120px to current left CSS position
  $( .plwid ).animate({
    left:  +=120 
  });
});
#plrt{
  position:relative;
  background:red;
  width:100px;
  height:100px;
  cursor:pointer;
}

.plwid{
  position:absolute;
  background:blue;
  width:100px;
  height:100px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<div id="plrt"></div>
<div class="plwid"></div>

尝试此 < a href=> "http://api.jquery.com/animate/" rel="no follow" >http://api.jquery.com/animate/

$( #plrt ).on( click , function() { 
    $( .plwid ).animate({ left:  +=120 , 5000 });     
}); 




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签