使元素“隐藏”朝向它的中心?
我注意到,在 JQuery 中使用 hide()
函数时,如下所示:
$("myDiv").hide("slow");
它总是“折叠”到div 的左上角。有什么办法可以让它向中心折叠吗? (在我所说的情况下,div 配置为“position:absolute;”)
I noticed that when using the hide()
function in JQuery, like this:
$("myDiv").hide("slow");
It always "folds" to the top-left corner of the div. Is there a way I could make it fold to the center? (In the case I'm talking about the div is configured "position: absolute;"
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
jQuery UI 有一个“缩放”效果,这可能就是你想要的:
http://jqueryui.com/demos/hide/
http://jsfiddle.net/TzzxZ/1/
jQuery UI has a "scale" effect which might be what you want:
http://jqueryui.com/demos/hide/
http://jsfiddle.net/TzzxZ/1/
在 2020 年,您(仍然)无法控制 hide() 函数在何处/如何缩小元素。然而,这就是我最近对类似情况进行排序的方法:
html 标记看起来像这样
css 看起来像这样
JQuery 现在可以用于隐藏元素“向中心”;即:该元素看起来好像保留在中间。
附带说明一下,您可能需要根据您的支持要求检查 Flex Box 的采用情况 https://caniuse.com/ #feat=flexbox 简而言之,在撰写本文时:IE 10 之前的版本、Opera 12.1 之前的版本、Opera mobile 12.1 之前的版本都无法运行; IE11 的支持很粗略。
噢,谢谢你2020,你真的很可爱!
In 2020 you (still) cannot control where/how the element is scaled down by the hide() function. However, this is how I sorted a similar situation recently:
The html markup looks like this
The css looks like this
JQuery can now be used to hide the element "towards the center"; ie: the element looks as if it was remaining in the middle.
As a side note, you might want to check flex box adoption against your support requirements https://caniuse.com/#feat=flexbox In short at the moment of writing this: IE before 10, Opera before 12.1, Opera mobile before 12.1 all aren't going to work; IE11 has a sketchy support.
Oh thank you 2020, you are really sweet!