通过后台定位元素-cssjquery
有什么方法可以定位与您的HTML元素相关的吗 页面的拉伸背景 你把背景拉长了 现在你想在你的标志旁边写点什么 考虑到分辨率和浏览器 CSS与JQuery 如果你知道任何策略或任何好文章/教程 我很高兴收到你的来信通过后台定位元素-cssjquery,jquery,css,Jquery,Css,有什么方法可以定位与您的HTML元素相关的吗 页面的拉伸背景 你把背景拉长了 现在你想在你的标志旁边写点什么 考虑到分辨率和浏览器 CSS与JQuery 如果你知道任何策略或任何好文章/教程 我很高兴收到你的来信 谢谢window.screen.width和window.screen.height可能会对您有所帮助。您可以计算窗口中的坐标以匹配拉伸的坐标。因此,如果背景图像从坐标(0,0)一直延伸到(window.screen.width,window.screen.height),图像大小为(
谢谢
window.screen.width
和window.screen.height
可能会对您有所帮助。您可以计算窗口中的坐标以匹配拉伸的坐标。因此,如果背景图像从坐标(0,0)一直延伸到(window.screen.width,window.screen.height),图像大小为(800600),并且您的徽标位于图像的坐标(44100)上,您希望知道窗口的坐标以匹配图像的坐标
function place(div, image_x, image_y, image_w, image_h)
{
//Calculate the window coordinates that match the image coordinates
var window_x = Math.Floor((window.screen.width/image_w)*image_x);
var window_y = Math.Floor((window.screen.height/image_h)*image_y);
//Make divs position absolute
$("#"+div).css("position", "absolute");
//Set the left in the window coords that match the images coords
$("#"+div).css("left", window_x+"px");
//Set the top to match the images coords
$("#"+div).css("top", window_y+"px");
}
您将使用如下函数:
place("logo_text_div", 44, 100, 800, 600);
您可以修改代码,使其使用Ceil,这样可以将坐标向右移动。或者你也可以用其他方法将窗口x和y围起来,这样你就可以得到你想要的预切割。你是如何将背景拉伸的?请显示一些代码。是的,我拉伸了图像并将其作为全屏背景。现在我想在我们在背景中看到的东西旁边放置一个元素,例如徽标。代码现在不可用。