0

我有一个固定的标题,当我到达窗口中的某个位置时,我想更改超链接的颜色。

我如何在 Jquery 中处理它?

4

5 回答 5

0

使用 $(window).scroll() 事件,您可以检查窗口的位置。

并在此基础上,您可以相应地设置超链接颜色。

像这样

 $('#links a').click(function(){
    $(this).addClass('selected');
    $(this).siblings().removeClass('selected');
});

试试这个 http://jsfiddle.net/TL9rh/

于 2013-10-07T10:21:14.110 回答
0

使用如下:

<!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>

您可以在不同的窗口位置使用各种颜色,如上

于 2013-10-07T10:16:57.857 回答
0

使用https://github.com/Prinzhorn/skrollr

示例 html:

<div id='header'>
    <a data-880='color: red'>Link</a>
</div>
于 2013-10-07T10:17:47.147 回答
0

收听滚动事件并检查 scrollTop...如果 scrollTop 参数到达您想要的位置,请更改链接的颜色。

于 2013-10-07T10:15:55.050 回答
0

尝试这个:

    $(window.parent.document).scroll(function() {
       if( $(this).offset().top >= xxx ){
           ....change text colour...
       }
    }
于 2013-10-07T10:16:27.337 回答