2011-07-26 47 views
1

我有以下代碼的jQuery JavaScript的條件語句

$(document).ready(function() { 

    $('.anipic').hover(function(){ 

     if ($(this).parent().position().left <= 700) { 
      $('.bio').css({ 
       'height': $(this).height()+2, 
       left: $(this).parent().width() 
      }); 
     } 

     if ($(this).parent().position().left >= 700) { 
      $('.bio').css({  
       'height': $(this).height()+2, 
       right: $(this).parent().width() 
      }); 
     } 

     $(this).css({'background-color':'#55CADF'}); 

     $(this).siblings('.bio').animate(
      { width: '+=160px' }, 
      { easing: 'swing', complete: function() { $('.biotext').fadeIn(); } } 
     ); 
    //endmouseover 
    }, 

    function() { 

     $(this).css({'background-color':'#ffffff'}); 

     $(this).siblings('.bio').stop().hide().css({'width':'0px'}) 
     $('.bio').hide(); 
     $('.biotext').hide(); 

    }) 
    //end 

//enddocumentready 
}); 

你可以在這裏看到的頁面http://afhboston.com/artists_listnew.php

基本上,一旦我將鼠標懸停在這該元素的條件語句被忽略的地位已經不如在它的父項中大於700px,並且位置大於700px的元素向左移動到右側。我沒有什麼好運算出這個bug。

回答

0

嘗試使用else而不是兩個ifs。我懷疑第二個條件總是成立,因爲你正在改變你正在檢查的內容。

if ($(this).parent().position().left <= 700){ 
    $('.bio').css({ 'height':$(this).height()+2,left:$(this).parent().width()}); 

    }else{ 

    $('.bio').css({ 'height':$(this).height()+2,right:$(this).parent().width()}); 
    } 
+0

我已經試過了。仍然是相同的結果。當您懸停在其他縮略圖上方時,最後一個縮略圖僅在左側動畫時懸停。一旦將鼠標懸停在位置不足700個的縮略圖上,所有縮略圖就會右移動。 – rya

+1

您可以發佈您的標記,以便我們可以更好地瞭解問題 –