2013-07-16 29 views
2

我使用精靈圖像來更改懸停時的背景並單擊(.keepImage類用於單擊)。它一切正常,但當背景圖片改變時,它會滾動到正確的位置。沒有滾動動作的方法嗎?使用CSS圖像精靈進行懸停效果而不使用滾動動畫

JS:

<script> 
     $(document).ready(function(){ 
      $("a.doing").click(function() { 
       $(this).siblings(".keepImage").removeClass("keepImage"); 
       $(this).addClass("keepImage"); 
      }); 
     }); 
</script> 

CSS:

a.doing { 
      width: 229px; 
      height: 202px; 
      margin-right: 8px; 
      background: url(http://localhost:8000/img/manifesto/spr_doing.png) 0 0; 
     } 
a.doing:hover, a.doing.keepImage { 
      background: url(http://localhost:8000/img/manifesto/spr_doing.png) -229px 0; 

     } 

回答

0

我想,在某個地方你的CSS您指定的過渡性質。通常,當你有一個如下所示的transition屬性:「transition:all 500ms ease;」時,背景位置會隨着滾動效果而改變。如果你想防止這種滾動發生,那麼你可以完全刪除轉換屬性,或者你可以使用轉換隻爲你想要動畫的屬性 - 如邊框,顏色等..但不是背景。如果你能以某種方式提供一個鏈接到你的頁面,或者給html標記和css,這將有所幫助。謝謝。