1

编辑:我已经得到了一个叉子,可以使用两个代码括号将 CSS 正确分配给 DOM,但是它不再居中在父 div 内。有任何想法吗?

查询:

$("#container").hover(function () {
$("#innerFocusPrompt").position({
    my: "center center",
    at: "center center",
    of: "#container"
});
$("#innerFocusPrompt").css({
    "display": "inherit"
}).fadeIn(100);
});

CSS:

#container {
background-color: black;
color: #121212;
height:400px;
width:400px;
margin: 0 auto;
margin-top: 50px;
}
#innerFocusPrompt {
display: none;
background-color: red;
color: black;
height:100px;
width:100px;
}

http://jsfiddle.net/WASasquatch/7C2dc/1/

4

2 回答 2

2

您正在协助css处理jQuery.position()程序。

您可以将其分配给 DOM,例如

$("#innerFocusPrompt").css({
    "display": "box"
});
于 2013-04-23T05:16:50.687 回答
1

你的语法不正确。您正在尝试将 .css 分配给元素的 position() 。

将您的代码更改为

$("#container").hover(function () {
   $("#innerFocusPrompt").position({
      my: "center center",
      at: "center center",
      of: "#container"
   });
   $("#innerFocusPrompt").css({
      "display": "box"
   });
});
于 2013-04-23T05:21:53.690 回答