2015-05-21 33 views
0

我使用http://web.enavu.com/demos/carousel.html的传送带。我想要第一个左图像是不透明的:1,其余不透明度:0.5。 :)获取传送带滑块中的第二个图像JQuery

任何人都可以帮忙吗?

谢谢。

<script type="text/javascript"> 
$(document).ready(function() { 
    //move he last list item before the first item. The purpose of this is if the user clicks to slide left he will be able to see the last item. 
    $('#carousel_ul li:first').before($('#carousel_ul li:last')); 


    //when user clicks the image for sliding right   
    $('#right_scroll img').click(function(){ 

     //get the width of the items (i like making the jquery part dynamic, so if you change the width in the css you won't have o change it here too) ' 
     var item_width = $('#carousel_ul li').outerWidth() + 10; 

     //calculae the new left indent of the unordered list 
     var left_indent = parseInt($('#carousel_ul').css('left')) - item_width; 

     //make the sliding effect using jquery's animate function ' 
     $('#carousel_ul:not(:animated)').animate({'left' : left_indent},500,function(){  

      //get the first list item and put it after the last list item (that's how the infinite effects is made) ' 
      $('#carousel_ul li:last').after($('#carousel_ul li:first')); 

      //and get the left indent to the default -210px 
      $('#carousel_ul').css({'left' : '-210px'}); 
     }); 
    }); 

    }); 
</script> 

<div id='carousel_container'> 
<div id='carousel_inner'> 
    <ul id='carousel_ul'> 
     <li><a href='#'><img src='item1.png' /></a></li> 
     <li><a href='#'><img src='item2.png' /></a></li> 
     <li><a href='#'><img src='item3.png' /></a></li> 
     <li><a href='#'><img src='item4.png' /></a></li> 
     <li><a href='#'><img src='item5.png' /></a></li> 
    </ul> 
</div> 

+0

@oMiKeY是,一些CSS样式就像一套不透明的。 – hahahaha

回答

1

jQuery中,抓住与

var middle = $('li').get(2); 

这将始终返回中心项目中心项目。就在这个查询运行后

$(middle).css('opacity, .2'); // adjust the translucency of the image 

添加onclick="changeMiddle()"到每个箭头按钮来触发此功能:

function changeMiddle() 
{ 
    var middle = $('li').get(2); // fetch middle image 
    $('li').css('opacity', '1'); // correct previous transparencies 
    $(middle).css('opacity', '.2'); // make middle image transparent 
} 
+0

我得到这个错误:Uncaught TypeError:undefined不是一个函数。我认为这是指middle.css('opacity','.2'); ,它不能中间。 – hahahaha

+0

我忘了,只要你使用'.get(#)'就会把你带出jQuery,所以你必须重新包装它。现在编辑... - 在那里,我在你提到的声明中重新进行了中间处理。 – oMiKeY

+0

非常感谢你! :D – hahahaha