gpt4 book ai didi

iphone - 尽管浏览器缩放级别保持 div 大小(相对于屏幕)

转载 作者:搜寻专家 更新时间:2023-10-31 08:38:01 24 4
gpt4 key购买 nike

我正在为我的 iPhone 创建一个小书签,它将在屏幕的左上角添加一个滚动菜单。我遇到的问题是,如果我访问一个可以放大的网站,当我放大时,我的“ float ”div 会随着我放大页面而变大。有没有办法让我的 div 宽度为 0.2 英寸(可以用卷尺测量,可以这么说),无论我在 Safari 浏览器中放大多远?

谢谢,奥利弗

最佳答案

这是我最终想出的解决方案(有很多评论。)

//This floating div function will cause a div to float in the upper right corner of the screen at all times. However, it's not smooth, it will jump to the proper location once the scrolling on the iPhone is done. (On my Mac, it's pretty smooth in Safari.) function flaotingDiv(){    //How much the screen has been zoomed.    var zoomLevel = ((screen.width)/(window.innerWidth));    //By what factor we must scale the div for it to look the same.    var inverseZoom = ((window.innerWidth)/(screen.width));    //The div whose size we want to remain constant.    var h = document.getElementById("fontSizeDiv");    //This ensures that the div stays at the top of the screen at all times. For some reason, the top value is affected by the zoom level of the Div. So we need to multiple the top value by the zoom level for it to adjust to the zoom.     h.style.top = (((window.pageYOffset) + 5) * zoomLevel).toString() + "px";    //This ensures that the window stays on the right side of the screen at all times. Once again, we multiply by the zoom level so that the div's padding scales up.    h.style.paddingLeft = ((((window.pageXOffset) + 5) * zoomLevel).toString()) + "px";    //Finally, we shrink the div on a scale of inverseZoom.    h.style.zoom = inverseZoom;}//We want the div to readjust every time there is a scroll event:window.onscroll = flaotingDiv;

关于iphone - 尽管浏览器缩放级别保持 div 大小(相对于屏幕),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3693281/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com