Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery animate()定位问题_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript jQuery animate()定位问题

Javascript jQuery animate()定位问题,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我正在开发我的个人网站,对它进行了一些修改 我实现了一种“手风琴”菜单功能,如果单击菜单按钮,“未单击”按钮消失,然后单击的按钮移动到列表的顶部,然后一个面板动画显示下来,我将在其中放置文本内容 在Firefox中,这一点非常有效,但是在IE和Chrome中,按钮会跳到页面顶部,然后设置动画到位置,而不是从开始的位置设置动画 有人知道如何解决这个问题吗 违规代码: function Accordion(e) { var o = { init: function() {

我正在开发我的个人网站,对它进行了一些修改

我实现了一种“手风琴”菜单功能,如果单击菜单按钮,“未单击”按钮消失,然后单击的按钮移动到列表的顶部,然后一个面板动画显示下来,我将在其中放置文本内容

在Firefox中,这一点非常有效,但是在IE和Chrome中,按钮会跳到页面顶部,然后设置动画到位置,而不是从开始的位置设置动画

有人知道如何解决这个问题吗

违规代码:

function Accordion(e)
 {
  var o =
  {
   init: function()
   {
    o.button = e;
    o.addClickHandler();
   },

   addClickHandler: function()
   {
    o.button.click(function(){
     o.button.removeClass('unselected');
     o.button.addClass('selected');
     o.fader();
    });
   },

   fader: function()
   {
    $j('.unselected').animate({opacity:0}, 1000);

    var wait = setInterval(function() {
     if(!$j('.unselected').is(":animated") ) {
      clearInterval(wait);
      o.shifter();
     }
    }, 100);
   },

   shifter: function()
   {
    o.button.css({'position':'absolute'});
    o.button.animate({top:91}, 500, o.createInfoBox);
   },

   createInfoBox: function()
   {
    var buttonParent = o.button.parent();
    buttonParent.append("<div class='infoBox'></div>");
    $j('.infoBox').animate({height:390});
   }
  }

  o.init();
  return o;
 }
}
功能手风琴(e)
{
var o=
{
init:function()
{
o、 按钮=e;
o、 addClickHandler();
},
addClickHandler:function()
{
o、 按钮。单击(函数(){
o、 按钮。removeClass(“未选择”);
o、 addClass('selected');
o、 音量控制器();
});
},
音量控制器:函数()
{
$j('.unselected')。动画({opacity:0},1000);
var wait=setInterval(函数(){
如果(!$j('.unselected')。为(“:动画”)){
清除间隔(等待);
o、 移位器();
}
}, 100);
},
移位器:函数()
{
o、 css({'position':'absolute'});
o、 动画({top:91},500,o.createInfoBox);
},
createInfoBox:function()
{
var buttonParent=o.button.parent();
按钮部分。追加(“”);
$j('.infoBox').animate({height:390});
}
}
o、 init();
返回o;
}
}
问题在于移位器功能,我将位置设置为绝对位置,然后设置动画,以便达到所需的效果。我理解它为什么这样做(假设它只是将自身重置为top:0,然后设置动画为top:91),但有人有快速解决方案吗?时间不早了,我的头都快累坏了

非常感谢


Dave

当您将元素切换到绝对位置时,是否尝试使用元素的当前位置。。。例如:

function() { 
  var currentp = $(this).offset();
  o.button.css({'position':'absolute', top: currentp.top}); 
  o.button.animate({top:91}, 500, o.createInfoBox); 
}
注意,有两种不同的抵销功能,我不确定您要在这里使用哪一种,因此您可能需要查看该功能上的文档


此外,您还可以随时重新设置jQueryUI的主题,省去麻烦;-)

很抱歉没有格式化,我发布的时候格式是正确的!您是否有指向相关页面的链接?
.offset()
,在某些情况下还有
.position()
,这取决于您是要针对视口还是父对象进行动画制作。我想我是在考虑
offsetParent()
。。我想我没有意识到
position()
这是1.4中的新功能吗?您好,非常感谢您的回复。尝试了.offset(),但实际计算的位置似乎在浏览器之间发生了变化。position()最终成功了,现在效果很好。再次感谢。