2013-08-17 62 views
0

我不能完全弄清楚爲什麼這不起作用。我有一些文字介紹右邊的圖片。當用戶滾動查看圖像時,我希望文字逐漸消失。我已經看到很多垂直文本使用相同的代碼淡入淡出的例子,但由於某種原因,這不適用於我。有人看到我做錯了什麼?我有以下的javascript代碼:水平滾動jQuery文本不透明

<script> 
    $(document).bind("projectLoadComplete", function(){ 
     if ($(".project_intro")[0]){ 
      var divs = $('.project_intro'); 
      $(window).bind('scroll', function() { 
       var st = $(this).scrollLeft(); 
       divs.css({ 'opacity' : (1 - st/250) }); 
       if (divs.css('opacity') < 0) { 
        divs.css('opacity', 0); 
       } 
      }); 
     } 
    }); 
</script> 

和下面的HTML代碼:

<div class="project_intro">This is some intro text that I want to fade when the user scrolls left.</div> 
<table height="100%" style="height: 100%; margin-left: 300px;" valign="middle"> 
    <tr> 
     <td>{image 1}</td> 
     <td>{image 2}</td> 
    </tr> 
</table> 
+0

看起來你的代碼是好的減去一些主觀的變化。我會看看[這個鏈接](http://support.cargocollective.com/customer/portal/questions/1282858-projectloadcomplete-not-triggering-)關於你的「綁定」。此外,如果您可以提供更多信息,例如控制檯中的任何錯誤,或者您可以手動觸發它,那將會很有用。 – Fluidbyte

回答

0

我在http://jsfiddle.net/5xQb3/6/

它爲我工作後,我更換了bind('projectLoadComplete ')document.ready()做了的jsfiddle你你確定你的projectLoadComplete事件正在發射嗎?

0
Don't go for the hardest thing dude. 
Use fadeOut jquery method... 
fadeOut('Ur time in milliseconds without quotes') 

$(document).ready(function(){ 
    if ($(".project_intro")[0]){ 
     var divs = $('.project_intro'); 
     $(window).bind('scroll', function() { 
      var st = $(this).scrollLeft(); 
      $('.project_intro').fadeOut(5000); 
     }); 
    } 
}); 

Demo