Position element through css

2020-05-09 22:24发布

what part of my code is wrong I keep getting invalid argument

I want to position the div element outside the document window on the left.

jQuery(this).css({"left": (jQuery(document).css("left") - jQuery(form).width())});

2条回答
SAY GOODBYE
2楼-- · 2020-05-09 23:18

Might want to tell "left" what measure your statement is in (px, %, etc)

查看更多
▲ chillily
3楼-- · 2020-05-09 23:20

document is the HTMLDocument instance. It's not an HTMLElement instance so no CSS styles apply to it. Consequently you can't read any left style from it. You can try document.documentElement (or $('html')) to get the root element child of the document, but I'm not sure what use you think reading its left style will be. (In reality: you'll get nothing.)

Are you really trying to position a div outside of the browser window? Obviously this cannot work; the whole idea of the window is that it constrains, clips and scrolls the document content inside it.

If you wanted to display content outside of the current browser window you would have to window.open a pop-up at a position based on the current window's screen position (screenLeft/screen.left etc). But pop-ups have many serious usability drawbacks and browsers limit their use for this reason.

查看更多
登录 后发表回答