How to use jQuery draggable with fixed position?

rafaello picture rafaello · Aug 4, 2010 · Viewed 14.8k times · Source

It works perfect in firefox, but in ie, chrome and opera it doesn't work.

<div> has position:fixed, and is .draggable()

and it doesn't work except firefox

Answer

ZiTAL picture ZiTAL · Apr 20, 2012

don't set fixed in CSS: it works in firefox, chromium, safari, iexplore

var div = $('#id');
div.resizable(
{
    stop: function(event, ui)
    {                       
        var top = getTop(ui.helper);
        ui.helper.css('position', 'fixed');
        ui.helper.css('top', top+"px");         
    }       
});
div.draggable(
{
    stop: function(event, ui)
    {           
        var top = getTop(ui.helper);
        ui.helper.css('position', 'fixed');
        ui.helper.css('top', top+"px");
    }
});

function getTop(ele)
{
    var eTop = ele.offset().top;
    var wTop = $(window).scrollTop();
    var top = eTop - wTop;

    return top; 
}