① js window.scroll 怎么判断滚动到底部
若要想判断js window.scroll是否滚动到底部,需要用的三个属性值,它们分别是:
scrollTop、clientHeight和scrollHeight;
1、scrollTop为滚动条在Y轴上的滚动距离。
2、clientHeight为内容可视区域的高度。
3、scrollHeight为内容可视区域的高度加上溢出(滚动)的距离。
so,滚动条到底部的条件即为scrollTop + clientHeight == scrollHeight。
② js点击按钮控制滚动条缓慢移动到底部
修改完成了 你把 你的js全部替换下即可
<scripttype="text/javascript">
varcurrentPosition,timer;
functionGoTop(){
currentPosition=document.documentElement.scrollTop;
currentPosition-=50;
if(currentPosition>0){
window.scrollTo(0,currentPosition);
timer=setInterval("GoTop()",10);
}else{
currentPosition=0;
window.scrollTo(0);
window.clearInterval(timer);
}
}
varcurrentPosition2,timer2;
functionGoBottom(){
currentPosition2=document.documentElement.scrollTop;
currentPosition2+=50;
if(currentPosition2<=1000){
window.scrollTo(0,currentPosition2);
timer2=setInterval("GoBottom()",100);
}else{
currentPosition=1000;
window.scrollTo(0,1000);
window.clearInterval(timer2);
}
}
</script>
③ JS/JAVASCRIPT 选中文本框内的文字 让滚动条滚动到选中文字的位置
function func(){
var textarea = document.getElementById("textarea");
//首先移动光标到所选文字位置,滚动条自动滚动
MoveCursortoPos('textarea' , 30 );
//再选中文字
textarea.setSelectionRange(30,32);//选中文本框内的文字
//textarea.scrollTop = textarea.scrollHeight;//滚动到底部
//想要修改成只滚动到 选中文字 的位置应该怎么写?
}
//设置光标位置
function MoveCursortoPos(id,pos){//定位光标到某个位置
var obj = document.getElementById(id); //获得元素
pos = pos ?pos :obj.value.length;
if (obj.createTextRange) {//IE浏览器 IE浏览器中有TextRange 对body,textarea,button有效
var range = obj.createTextRange(); //创建textRange
range.moveStart("character", pos); //移动开始点,以字符为单位
range.collapse(true);//没有移动结束点直接 折叠到一个点
range.select();//选择这个点
} else {//非IE浏览器
obj.setSelectionRange(obj.value.length, pos);
}
obj.focus();
}
④ 关于像hao123首页的“到底部”的JS效果如何实现
<a href="#ct1">跳转到词条1</a>
<a href="#ct2">跳转到词条2</a>
<br>
<div id="ct1" style="height:1000px;">词条1</div>
<div id="ct2">词条2</div>
⑤ JS 让div始终浮动在浏览器底部
body{margin:0;padding:010px010px;height:100%;overflow:auto;background:#333;font-size:12px;}
#wrap{display:block;bottom:0px;right:1px!important;right:18px;width:200px;line-height:30px;position:fixed;border:1pxsolid#fff;text-align:center;color:#fff;background:#000;}
*html{overflow-x:auto;overflow-y:auto;}
*html#wrap{position:absolute;}
上面是样式部分
<divstyle="height:3986px;"></div>
<divid="wrap">我是不会动的,只有这个地方是属于我的,在你没有更改我的位置之前。<br>
<ahref="http://www.CsrCode.cn">CsrCode.CN</a>丨<ahref="http://www.CsrCode.cn">芯晴网页特效</a>丨<ahref="http://www.CsrCode.cn">seo优化</a>
这是HTML部分
开玩笑!你直接复制过去!
页面的其他部分有没有设置定位!有的话删除!
自己看有没有在。看下自己页面其他地方有没设置定位。有的话删了
⑥ 一段js用来控制左侧的导航栏滑到底部时固定右侧继续滑动,但问题是将页面滚动到下边刷新左边不会滚下来了
依靠css 将页面
document.documentElement.style.overflow='hidden';
document.body.style.overflow='hidden';//手机版设置这个。
如果设置了如上,页面的滚动条将会专消失,此时鼠标滚轮失效属。