admin管理员组文章数量:1023058
I am using the following code to scroll scroll an element on mouseDown, and stop scrolling on mouseUp/mouseOut.
scrubby(xDir) {
let dub = setInterval(() => {
document.getElementById("chart").scrollBy(8 * xDir, 0);
}, 10);
this.setState({ dub: dub });
}
scrubbyStop() {
const { dub } = this.state;
if (dub !== null) {
clearInterval(dub);
}
this.setState({ dub: null });
}
This works everywhere except IE 11. In IE 11 I get the following error:
TypeError: Object doesn't support property or method 'scrollBy'
When I console.log the element, the document.getElementById to ensure I am selecting the element.
I am using babel-polyfil
I see a lot of questions related to scrollTo, but not scrollBy. Does anyone know any workarounds, polyfill or alternatives that might work for IE.
I am using the following code to scroll scroll an element on mouseDown, and stop scrolling on mouseUp/mouseOut.
scrubby(xDir) {
let dub = setInterval(() => {
document.getElementById("chart").scrollBy(8 * xDir, 0);
}, 10);
this.setState({ dub: dub });
}
scrubbyStop() {
const { dub } = this.state;
if (dub !== null) {
clearInterval(dub);
}
this.setState({ dub: null });
}
This works everywhere except IE 11. In IE 11 I get the following error:
TypeError: Object doesn't support property or method 'scrollBy'
When I console.log the element, the document.getElementById to ensure I am selecting the element.
I am using babel-polyfil
I see a lot of questions related to scrollTo, but not scrollBy. Does anyone know any workarounds, polyfill or alternatives that might work for IE.
Share Improve this question asked Oct 13, 2018 at 13:22 FinglishFinglish 9,99615 gold badges77 silver badges118 bronze badges 02 Answers
Reset to default 5Babel polyfill "will emulate a full ES2015+ environment". However, scrollBy
is not part of the ECMAScript specification and thus will not be polyfilled by Babel.
You need to add a proper polyfill by yourself, for example smooth scroll behaviour polyfill which also includes scrollBy
.
I'm over a year late to this question, but if anyone else is facing this issue and wants a solution that only fills in scrollBy
, I'm using jQuery:
<script src="https://ajax.googleapis./ajax/libs/jquery/3.4.1/jquery.min.js"></script>
...and adding this to my page's JavaScript:
if(!window.scrollBy){
window.scrollBy = function(x, y){
if(x) $('html, body').scrollLeft($(window).scrollLeft() + x);
if(y) $('html, body').scrollTop($(window).scrollTop() + y);
};
}
if(!Element.prototype.scrollBy){
Element.prototype.scrollBy = function(x, y){
if(x) $(this).scrollLeft($(this).scrollLeft() + x);
if(y) $(this).scrollTop($(this).scrollTop() + y);
};
}
It's tested and working in IE 11.
I am using the following code to scroll scroll an element on mouseDown, and stop scrolling on mouseUp/mouseOut.
scrubby(xDir) {
let dub = setInterval(() => {
document.getElementById("chart").scrollBy(8 * xDir, 0);
}, 10);
this.setState({ dub: dub });
}
scrubbyStop() {
const { dub } = this.state;
if (dub !== null) {
clearInterval(dub);
}
this.setState({ dub: null });
}
This works everywhere except IE 11. In IE 11 I get the following error:
TypeError: Object doesn't support property or method 'scrollBy'
When I console.log the element, the document.getElementById to ensure I am selecting the element.
I am using babel-polyfil
I see a lot of questions related to scrollTo, but not scrollBy. Does anyone know any workarounds, polyfill or alternatives that might work for IE.
I am using the following code to scroll scroll an element on mouseDown, and stop scrolling on mouseUp/mouseOut.
scrubby(xDir) {
let dub = setInterval(() => {
document.getElementById("chart").scrollBy(8 * xDir, 0);
}, 10);
this.setState({ dub: dub });
}
scrubbyStop() {
const { dub } = this.state;
if (dub !== null) {
clearInterval(dub);
}
this.setState({ dub: null });
}
This works everywhere except IE 11. In IE 11 I get the following error:
TypeError: Object doesn't support property or method 'scrollBy'
When I console.log the element, the document.getElementById to ensure I am selecting the element.
I am using babel-polyfil
I see a lot of questions related to scrollTo, but not scrollBy. Does anyone know any workarounds, polyfill or alternatives that might work for IE.
Share Improve this question asked Oct 13, 2018 at 13:22 FinglishFinglish 9,99615 gold badges77 silver badges118 bronze badges 02 Answers
Reset to default 5Babel polyfill "will emulate a full ES2015+ environment". However, scrollBy
is not part of the ECMAScript specification and thus will not be polyfilled by Babel.
You need to add a proper polyfill by yourself, for example smooth scroll behaviour polyfill which also includes scrollBy
.
I'm over a year late to this question, but if anyone else is facing this issue and wants a solution that only fills in scrollBy
, I'm using jQuery:
<script src="https://ajax.googleapis./ajax/libs/jquery/3.4.1/jquery.min.js"></script>
...and adding this to my page's JavaScript:
if(!window.scrollBy){
window.scrollBy = function(x, y){
if(x) $('html, body').scrollLeft($(window).scrollLeft() + x);
if(y) $('html, body').scrollTop($(window).scrollTop() + y);
};
}
if(!Element.prototype.scrollBy){
Element.prototype.scrollBy = function(x, y){
if(x) $(this).scrollLeft($(this).scrollLeft() + x);
if(y) $(this).scrollTop($(this).scrollTop() + y);
};
}
It's tested and working in IE 11.
本文标签: javascriptObject doesn39t support property or method 39scrollBy39 in IE11 in ReactStack Overflow
版权声明:本文标题:javascript - Object doesn't support property or method 'scrollBy' in IE11 in React - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745500681a2153377.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论