获取旋转木马滑块JQuery中的第二个图像

时间:2015-05-21 04:04:49

标签: jquery carousel

我正在使用来自http://web.enavu.com/demos/carousel.html的轮播。我希望第一个左图像是不透明度:1,其余不透明度:0.5。 :)

任何人都可以提供帮助吗?

谢谢。

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

  

1 个答案:

答案 0 :(得分: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
}