我有一些画廊的js代码,但控制台显示以下错误。
function stopMovement() {
clearInterval(leftInterval);
clearInterval(rightInterval);
}
leftBtn.addEventListener('mouseenter', moveLeft);
leftBtn.addEventListener('mouseleave', stopMovement);
rightBtn.addEventListener('mouseenter', moveRight);
rightBtn.addEventListener('mouseleave', stopMovement);
//Start this baby up
(function init() {
var images = [
'Images/Gallery/1.jpg',
'http://mymodernmet.com/wp/wp-content/uploads/2017/03/Conrad-Maldives-Rangali-Island.jpeg',
'Images/Gallery/3.jpg',
'Images/Gallery/4.jpg'
];
错误消息:
Uncaught TypeError: Cannot read property 'addEventListener' of null
at gallery.js:89
(anonymous) @ gallery.js:89
答案 0 :(得分:0)
您的leftBtn
和RightBtn
变量未声明或未正确声明,因此该错误表明您正在尝试访问null值上的addEventListener属性