Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.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 如何修改一个小脚本以在没有jquery的情况下运行_Javascript_Jquery_Css_Scrollbar - Fatal编程技术网

Javascript 如何修改一个小脚本以在没有jquery的情况下运行

Javascript 如何修改一个小脚本以在没有jquery的情况下运行,javascript,jquery,css,scrollbar,Javascript,Jquery,Css,Scrollbar,下面的Script2平行滚动条只有几行,但需要jquery库,如何使其成为独立的javascript,提前感谢 HTML: CSS: 这就是为什么: var scrollBarTop = document.querySelector(".wrapper1"); var scrollBarBottom = document.querySelector(".wrapper2"); scrollBarTop.addEventListener("scroll", function(){ scr

下面的Script2平行滚动条只有几行,但需要jquery库,如何使其成为独立的javascript,提前感谢

HTML:

CSS:

这就是为什么:

var scrollBarTop = document.querySelector(".wrapper1");
var scrollBarBottom = document.querySelector(".wrapper2");

scrollBarTop.addEventListener("scroll", function(){
    scrollBarBottom.scrollLeft = scrollBarTop.scrollLeft;    
});

scrollBarBottom.addEventListener("scroll", function(){
    scrollBarTop.scrollLeft = scrollBarBottom.scrollLeft;    
});
这就是为什么:

var scrollBarTop = document.querySelector(".wrapper1");
var scrollBarBottom = document.querySelector(".wrapper2");

scrollBarTop.addEventListener("scroll", function(){
    scrollBarBottom.scrollLeft = scrollBarTop.scrollLeft;    
});

scrollBarBottom.addEventListener("scroll", function(){
    scrollBarTop.scrollLeft = scrollBarBottom.scrollLeft;    
});

这是一种有角度的方法。i、 没有Jquery

奇怪的是,您不能只设置变量,而必须直接对文档进行设置


这是一种有角度的方法。i、 没有Jquery

奇怪的是,您不能只设置变量,而必须直接对文档进行设置


你想要javascript中的代码和你在jquery中所做的一样?你想要javascript中的代码和你在jquery中所做的一样?
.wrapper1, .wrapper2{width: 300px; border: none 0px RED;
overflow-x: scroll; overflow-y:hidden;}
.wrapper1{height: 20px; }
.wrapper2{height: 200px; }
.div1 {width:1000px; height: 20px; }
.div2 {width:1000px; height: 200px; background-color: #88FF88;
overflow: auto;}
var scrollBarTop = document.querySelector(".wrapper1");
var scrollBarBottom = document.querySelector(".wrapper2");

scrollBarTop.addEventListener("scroll", function(){
    scrollBarBottom.scrollLeft = scrollBarTop.scrollLeft;    
});

scrollBarBottom.addEventListener("scroll", function(){
    scrollBarTop.scrollLeft = scrollBarBottom.scrollLeft;    
});
import { Component, ViewEncapsulation } from '@angular/core';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
  encapsulation: ViewEncapsulation.Emulated
 })
export class AppComponent {

onWindowsScrollTop() {
  document.querySelector('.table-wrapper-bottom').scrollLeft = document.querySelector('.table-wrapper-top').scrollLeft;
}
onWindowsScrollBottom() {
  document.querySelector('.table-wrapper-top').scrollLeft = document.querySelector('.table-wrapper-bottom').scrollLeft;
}

reportTopScrollLeft() {
  alert('the scrollLeft for top = ' + document.querySelector('.table-wrapper-top').scrollLeft)
}

reportBottomScrollLeft() {
  alert('the scrollLeft for top = ' + document.querySelector('.table-wrapper-bottom').scrollLeft)
}

 }