简体   繁体   English

jQuery悬停以设置左侧位置在IE中不起作用?

[英]jQuery hover to set position left doesn't work in IE?

I'm having an issue making the follow code work in ANY version of IE. 我在使以下代码在任何版本的IE中都能正常工作时遇到问题。 The div that should be showing up simply does not appear on hover at all... 应该显示的div根本不会出现在悬停上...

$('.trigger').hover(function() {
    $(this).css({'height':'390px','width':'475px'});
    $(this).find('.preview_window').css('left', '0px');
},
function(){
    $(this).css({'height':'29px','width':'29px'});
    $(this).find('.preview_window').css('left', '-9999px');
}
);

It's GOT to be something really stupid... seeing as how it works on everything but IE across the board. 这真是一件愚蠢的事情……看到它在除IE之外的所有产品上如何工作。 Can anyone shed some light? 谁能阐明一些想法?

I think you must add the position attribute to that div : 我认为您必须将position属性添加到该div:

preview_window {
    position: relative;
}

You may need to specifically define the position method like this: 您可能需要像下面这样专门定义position方法:

$('.trigger').hover(function() {
    $(this).css({'height':'390px','width':'475px'});
    $(this).find('.preview_window').css({'position':'absolute','left':'0px'});
},
function(){
    $(this).css({'height':'29px','width':'29px'});
    $(this).find('.preview_window').css({'position':'absolute','left':'-9999px'});
});

Turns out IE just didn't like where I was putting line breaks in the function... 事实证明IE只是不喜欢我在函数中放置换行符的位置...

Here is the changed code that IE can apparently understand better. 这是IE显然可以更好地理解的更改代码。

$('.trigger').hover(function() {
    $(this).css({'height':'390px','width':'475px'});
    $(this).find('.preview_window').css('left', '0px');
},function(){ //This was also on two lines before
    $(this).css({'height':'29px','width':'29px'});
    $(this).find('.preview_window').css('left', '-9999px');
}); // This was on two lines before

I knew it was something stupid. 我知道那是愚蠢的事。 Everything works now. 现在一切正常。 =/ = /

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM