Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css webkit溢出滚动:获取Y位置_Css - Fatal编程技术网

Css webkit溢出滚动:获取Y位置

Css webkit溢出滚动:获取Y位置,css,Css,如何获取此滚动条的Y位置 .cool-scroll{ overflow-y:scroll; -webkit-overflow-scrolling:touch; } 我的目的是在背景颜色超过Y轴的N值时更改背景颜色 这里有一个使用jQuery的解决方案,代码将侦听元素上的滚动事件,并在到达目标位置时应用一个新类 Javascript var targetScroll = 200; $('.cool-scroll').scroll(function(){ if($(this).scrol

如何获取此滚动条的
Y
位置

.cool-scroll{
overflow-y:scroll;
-webkit-overflow-scrolling:touch;
}

我的目的是在背景颜色超过
Y
轴的
N
值时更改背景颜色

这里有一个使用jQuery的解决方案,代码将侦听元素上的滚动事件,并在到达目标位置时应用一个新类

Javascript

var targetScroll = 200;
$('.cool-scroll').scroll(function(){
    if($(this).scrollTop() > targetScroll)
        $(this).addClass('scrolled');
    else
        $(this).removeClass('scrolled');
});
CSS

.cool-scroll.scrolled{
    background: red;
}

您可能需要使用javascript或jQuery。您好,谢谢,我必须使用.css()吗@user1671639Nope
。滚动
将帮助您。让我试一试。