[英]IE9 Jquery slider not opening
I need help debugging slider in IE9. 我需要帮助来调试IE9中的滑块。 It does not open the slider, here is the javascript code. 它不会打开滑块,这是JavaScript代码。
<script>
var $root = $('html, body');
$('a').click(function() {
var href = $.attr(this, 'href');
$root.animate({
scrollTop: $(href).offset().top
}, 500, function () {
window.location.hash = href;
});
return false;
});
// yeah let's do vanilla JS just for fun :P
var toggle = document.getElementsByClassName('toggle');
var slider = document.querySelector('.slider');
for(var i = 0; i < toggle.length; i++) {
toggle[i].addEventListener('click', toggleSlider, false);
}
function toggleSlider(){
if (slider.classList.contains('opened')) {
slider.classList.remove('opened');
slider.classList.add('closed');
} else {
slider.classList.remove('closed');
slider.classList.add('opened');
}
}
</script>
When using IE develop tools IE generates this error "Unable to get value of the property 'top' : object is null or undefined" 使用IE开发工具时,IE会生成此错误“无法获取属性'top'的值:对象为null或未定义”
Then it shows the possible area of where the error is occuring: 然后显示发生错误的可能区域:
$root.animate({
scrollTop: $(href).offset().top
}, 500, function () {
window.location.hash = href;
});
Any ideas whats going on here? 有什么想法吗?
Your problem is in this line: 您的问题在这一行:
var href = $.attr(this, 'href');
This will not work because its trying to set 'this' attribute of the jquery object to href and that is not going to work for several reasons. 这将不起作用,因为它试图将jquery对象的'this'属性设置为href,并且由于多种原因而无法起作用。 What you probably want to do is something like this: 您可能想做的是这样的:
var href = $(".selector").attr('href');
Try to use: 尝试使用:
var href = $(this).attr('href');
instead of: 代替:
var href = $.attr(this, 'href');
inside the click handler of your anchor. 在锚点的点击处理程序中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.