简体   繁体   中英

Draggable div on top of entire page (on page load)

I am working on a web project that should include a draggable element, which I placed in the page using javascript and jquery .

Everything is working as intended, but the div which is draggable takes up some space between the div above and below it. I would like this draggable element to be on top of the rest of the page right after loading the page, ie I would like it to not take up space between the div above and the div below but to be generated on top of everything. See the video and jsfiddle below.

How might I be able to accomplish this?

Draggable_Cat

JSFiddle

Use position:absolute; like this:

$(function() {
  $("#draggable").draggable().css("position", "absolute");;
});

Updated Jsfiddle .

Also, In your CSS, you were using the wrong selector type. In your HTML you had the id draggable and in your CSS you were using it as a class.

Change your CSS as given below:

.draggable { 
    z-index: 4000;
    width: 350px; 
    height: 350px; 
    padding: 0em;
}

with this:

#draggable { 
    z-index: 4000;
    width: 350px; 
    height: 350px; 
    padding: 0em;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM