Javascript 更改窗口滚动条上的文本颜色
我有一个固定的标题,当我到达窗口中的某个位置时,我想更改超链接的颜色Javascript 更改窗口滚动条上的文本颜色,javascript,jquery-ui,css,Javascript,Jquery Ui,Css,我有一个固定的标题,当我到达窗口中的某个位置时,我想更改超链接的颜色 如何在Jquery中执行此操作?请收听scroll事件并在scrollTop上进行检查……如果scrollTop参数达到您所需的位置,请更改链接的颜色。尝试以下操作: $(window.parent.document).scroll(function() { if( $(this).offset().top >= xxx ){ ....change text colour...
如何在Jquery中执行此操作?请收听scroll事件并在scrollTop上进行检查……如果scrollTop参数达到您所需的位置,请更改链接的颜色。尝试以下操作:
$(window.parent.document).scroll(function() {
if( $(this).offset().top >= xxx ){
....change text colour...
}
}
使用方法如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(e)
{
$(window).scroll(function() {
var currpos = $(window).scrollTop();
if(currpos < 199)
{
if(currpos > 100)
{
$(".header").attr("color","red");
//$('#header').fadeTo(1,0.8,function(){});
}
}
else if(currpos < 299)
{
if(currpos > 200)
{
$(".header").attr("color","red");
//$('#header').fadeTo(1,0.6,function(){});
}
}
else if(currpos < 399)
{
if(currpos > 300)
{
$(".header").attr("color","red");
//$('#header').fadeTo(1,0.4,function(){});
}
}
else
{
$(".header").attr("color","red");
}
});
});
</script>
</head>
<body style="height:2000px;">
</body>
</html>
无标题文件
$(文档).ready(函数(e)
{
$(窗口)。滚动(函数(){
var currpos=$(window.scrollTop();
如果(当前位置<199)
{
如果(当前位置>100)
{
$(“.header”).attr(“颜色”、“红色”);
//$('#header').fadeTo(1,0.8,function(){});
}
}
否则,如果(当前位置<299)
{
如果(当前位置>200)
{
$(“.header”).attr(“颜色”、“红色”);
//$('#header').fadeTo(1,0.6,function(){});
}
}
否则,如果(当前位置<399)
{
如果(当前位置>300)
{
$(“.header”).attr(“颜色”、“红色”);
//$('#header').fadeTo(1,0.4,function(){});
}
}
其他的
{
$(“.header”).attr(“颜色”、“红色”);
}
});
});
您可以在不同的窗口位置使用不同的颜色,如上所述
html示例:
链接
使用$(window).scroll()事件可以检查窗口的位置
并在此基础上设置相应的超链接颜色
像这样
$('#links a').click(function(){
$(this).addClass('selected');
$(this).siblings().removeClass('selected');
});
试试这个