An alternative to -webkit-transform: transformY?

吃可爱长大的小学妹 提交于 2019-12-21 02:49:12

问题


I'm creating a chrome extension that displays an iframe on the top of specific pages. This iframe is fixed and placed before opening body tag.

To reserve a place for this iframe, I shift down the body including fixed element using CSS :

-webkit-transform: translateY(40px);

It seems to work fine with many websites, but on some other website such as facebook it causes a problem. a scroll bar is shown on the right side.

Is there an alternative that I might try to avoid this problem . Any help would be appreciated


回答1:


Just go one Node higher. And, you'll guess it, it's the html element. Unfortunately, I don't know a way to access it like the body: document.body.

But I found an easy way, use document.body.parent.

And there, you set the css property.

document.body.parent.style.webkitTransform = 'translateY(40px)';

Just besides, margin-top works too:

document.body.parent.style.marginTop = '40px';



来源:https://stackoverflow.com/questions/17305278/an-alternative-to-webkit-transform-transformy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!