div不能正确地从左向右移动 [英] div is not moving from left to right correctly

查看:163
本文介绍了div不能正确地从左向右移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我用来将div从左向右移动的代码段.

Below is my code snippet which i am using to move a div from left to right.

https://jsfiddle.net/nf6pqbr0/1/u/

$( "#go" ).click(function() {
  var stop = $(".stopdiv").offset().left;
  var obj = document.getElementById("audio"); 

  $( ".move" ).animate({
    opacity: 0.25,
    left: stop-($(".stopdiv").width()+$(this).width()),
  }, {
    duration: 1000, 
    step: function(){
        $('.sound').each(function(){

            });

  }, complete: function() {
    $(this).css('left',0);
    $(this).css('height','100%');

  }});


});

推荐答案

要设置元素的左侧,应将其位置设置 relative/fixed/absolute

To set a left to element you should set the position to it relative/fixed/absolute

在您的情况下,将.move的位置设置为相对位置

.move{position:relative;background:green;width:2px; height:100px;}

工作示例

另一个 演示 ,您可以看一下

Another Demo you can take a look at it

这篇关于div不能正确地从左向右移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆