获取页面位置和div位置 博客分类: JavaScript scrolltop
程序员文章站
2024-02-25 20:43:51
...
var ch=(document.documentElement.scrollTop+document.documentElement.clientHeight-box.offsetHeight);
var cw=(document.documentElement.scrollLeft+document.documentElement.clientWidth-box.offsetWidth);
var top=parseInt(box.style.top);
var left=parseInt(box.style.left);
ch=页面高度
cw=页面宽度
top=id为box的div高度
left=id为box的div宽度
var ch=(document.documentElement.scrollTop+document.documentElement.clientHeight-favoriteDiv.offsetHeight);
var cw=(document.documentElement.scrollLeft+document.documentElement.clientWidth-favoriteDiv.offsetWidth);
var top = parseInt(favoriteDiv.style.top);
var left = parseInt(favoriteDiv.style.left);
var speed=1;
if(top>=ch && left<=cw)
{
favoriteDiv.style.top = ch;
favoriteDiv.style.left = left;
}
else if(top <= ch && left >= cw)
{
favoriteDiv.style.top = top;
favoriteDiv.style.left = cw;
}
else if(top >= ch && left >= cw)
{
favoriteDiv.style.top = ch;
favoriteDiv.style.left = cw;
}
var cw=(document.documentElement.scrollLeft+document.documentElement.clientWidth-box.offsetWidth);
var top=parseInt(box.style.top);
var left=parseInt(box.style.left);
ch=页面高度
cw=页面宽度
top=id为box的div高度
left=id为box的div宽度
var ch=(document.documentElement.scrollTop+document.documentElement.clientHeight-favoriteDiv.offsetHeight);
var cw=(document.documentElement.scrollLeft+document.documentElement.clientWidth-favoriteDiv.offsetWidth);
var top = parseInt(favoriteDiv.style.top);
var left = parseInt(favoriteDiv.style.left);
var speed=1;
if(top>=ch && left<=cw)
{
favoriteDiv.style.top = ch;
favoriteDiv.style.left = left;
}
else if(top <= ch && left >= cw)
{
favoriteDiv.style.top = top;
favoriteDiv.style.left = cw;
}
else if(top >= ch && left >= cw)
{
favoriteDiv.style.top = ch;
favoriteDiv.style.left = cw;
}
上一篇: 为Android Studio编写自定义Gradle插件的教程
下一篇: 运营模式 博客分类: 概念