简体   繁体   中英

How to put a div on the very top of the page using jQuery or javascript?

I use a scrolling navigation so as the navigation is folowing the user and no need to go to the top to change the page.

Because the page is an app page, on the very very top of it i want to add something like this :

在此处输入图片说明

My problem is that the scrolling navigation has a really hardcoded css structure, and my question is if there is a javascript/jQuery way to just put that new div block at the top of everything.

Thank you

you can simply try:

#new-div-id {
        position:fixed;
        top:0px;
        left: 0px;
        z-index: 999; 
    }

您可以尝试以下方法:

container.insertBefore(newElement, container.firstChild);

If you don't want to do it using CSS

here is jquery code

$(document).ready(function(){
    $("#new-div-id").css({"position":"fixed", "top":"0px", "left":"0px", "z-index", 9999 });
});

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