Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/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
Javascript 根据滚动条位置更改元素的不透明度_Javascript_Jquery - Fatal编程技术网

Javascript 根据滚动条位置更改元素的不透明度

Javascript 根据滚动条位置更改元素的不透明度,javascript,jquery,Javascript,Jquery,我试图根据滚动条的位置改变元素的不透明度,但是函数总是会在第一个“else if”之后停止,因此即使函数仍然检测到滚动条的位置,元素“C”、“D”、“E”也不会发生任何变化 $(document).ready(function() { $(window).scroll(function(event) { var scroll = $(window).scrollTop(); if (scroll < 600) { docume

我试图根据滚动条的位置改变元素的不透明度,但是函数总是会在第一个“else if”之后停止,因此即使函数仍然检测到滚动条的位置,元素“C”、“D”、“E”也不会发生任何变化

$(document).ready(function() {   
      $(window).scroll(function(event) {
        var scroll = $(window).scrollTop();

      if (scroll < 600) {
        document.getElementById("A").style.opacity = "1";
        document.getElementById("B").style.opacity = "0.5";
        document.getElementById("C").style.opacity = "0.5";
        document.getElementById("D").style.opacity = "0.5";
      } 
      else if (600 <= scroll < 1500) {
        document.getElementById("A").style.opacity = "0.5";
        document.getElementById("B").style.opacity = "1";
        document.getElementById("C").style.opacity = "0.5";
        document.getElementById("D").style.opacity = "0.5";
      } 
      else if (1500 <= scroll < 2600) {
        document.getElementById("A").style.opacity = "0.5";
        document.getElementById("B").style.opacity = "0.5";
        document.getElementById("C").style.opacity = "1";
        document.getElementById("D").style.opacity = "0.5";
      } 
      else if (2600 <= scroll < 3200) {
        document.getElementById("A").style.opacity = "0.5";
        document.getElementById("B").style.opacity = "0.5";
        document.getElementById("C").style.opacity = "0.5";
        document.getElementById("D").style.opacity = "1";
$(文档).ready(函数(){
$(窗口)。滚动(功能(事件){
var scroll=$(窗口).scrollTop();
如果(滚动<600){
document.getElementById(“A”).style.opacity=“1”;
document.getElementById(“B”).style.opacity=“0.5”;
document.getElementById(“C”).style.opacity=“0.5”;
document.getElementById(“D”).style.opacity=“0.5”;
} 

否则,如果(600你不能做x
$(document).ready(function() {   
  $(window).scroll(function(event) {
    var scroll = $(window).scrollTop();

  if (scroll < 600) {
    document.getElementById("A").style.opacity = "1";
    document.getElementById("B").style.opacity = "0.5";
    document.getElementById("C").style.opacity = "0.5";
    document.getElementById("D").style.opacity = "0.5";
  } 
  else if (600 <= scroll && scroll < 1500) {
    document.getElementById("A").style.opacity = "0.5";
    document.getElementById("B").style.opacity = "1";
    document.getElementById("C").style.opacity = "0.5";
    document.getElementById("D").style.opacity = "0.5";
  } 
  else if (1500 <= scroll && scroll < 2600) {
    document.getElementById("A").style.opacity = "0.5";
    document.getElementById("B").style.opacity = "0.5";
    document.getElementById("C").style.opacity = "1";
    document.getElementById("D").style.opacity = "0.5";
  } 
  else if (2600 <= scroll && scroll < 3200) {
    document.getElementById("A").style.opacity = "0.5";
    document.getElementById("B").style.opacity = "0.5";
    document.getElementById("C").style.opacity = "0.5";
    document.getElementById("D").style.opacity = "1";
$(文档).ready(函数(){
$(窗口)。滚动(功能(事件){
var scroll=$(窗口).scrollTop();
如果(滚动<600){
document.getElementById(“A”).style.opacity=“1”;
document.getElementById(“B”).style.opacity=“0.5”;
document.getElementById(“C”).style.opacity=“0.5”;
document.getElementById(“D”).style.opacity=“0.5”;
} 

否则,如果(600天哪,我太笨了xD,谢谢你的工作!对不起,我对这东西有点陌生