簡體   English   中英

jQuery懸停以設置左側位置在IE中不起作用?

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

我在使以下代碼在任何版本的IE中都能正常工作時遇到問題。 應該顯示的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');
}
);

這真是一件愚蠢的事情……看到它在除IE之外的所有產品上如何工作。 誰能闡明一些想法?

我認為您必須將position屬性添加到該div:

preview_window {
    position: relative;
}

您可能需要像下面這樣專門定義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'});
});

事實證明IE只是不喜歡我在函數中放置換行符的位置...

這是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

我知道那是愚蠢的事。 現在一切正常。 = /

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM