如何从JQuery Slider中删除Opcity

时间:2014-03-09 18:05:15

标签: javascript jquery html css

我正在使用jquery作为我的图像滑块。我的滑块工作正常,但有一个问题。当图片互相交换时,由于不透明度,我可以看到当前图片上最后一张图片的反射,我希望当新图片进入Slider时,应该没有最后一张图片的反射, 这是我的代码

    <script type="text/javascript" src="jquery-1.2.6.min.js"></script>
    <script type="text/javascript">
    function slideSwitch() {
        var $active = $('#slideshow IMG.active');

        if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

        // use this to pull the images in the order they appear in the markup
        var $next =  $active.next().length ? $active.next()
            : $('#slideshow IMG:first');

        // uncomment the 3 lines below to pull the images in random order

        // var $sibs  = $active.siblings();
        // var rndNum = Math.floor(Math.random() * $sibs.length );
        // var $next  = $( $sibs[ rndNum ] );


        $active.addClass('last-active');

        $next.css({opacity: 1.0})
            .addClass('active')
            .animate({opacity: 1}, 1000, function() {
                $active.removeClass('active last-active');
            });
    }

    $(function() {
        setInterval( "slideSwitch()", 3000 );
    });

    </script>
<div id="slideshow">  
    <img src="FrontPage Images/background2.png"  style="width: 1158PX;
left: 0px;
top: 0px;
height: 230px;"/>
    <img src="FrontPage Images/background3.png"  style="width: 1158PX;
left: 0px;
top: 0px;
height: 230px;" />
     <img src="FrontPage Images/background4.png" style="width: 1158PX;
left: 0px;
top: 0px;
height: 230px;"/>
</div>

1 个答案:

答案 0 :(得分:1)

尝试使用此代码,以便您的图像渐渐淡出并循环播放:

jQuery的:

$(document).ready(function ()
{
var change = function()
{
    var current = ($('div.contain img.show') ? $('div.contain img.show') : $('div.contain img:first'));
    if (!current.length) current = $('div.contain img:first');
   var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div.contain img:first') : current.next()) : $('div.contain img:first'));

   // var $active = $('#slideshow IMG.active');

   /*

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');


    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    // uncomment the 3 lines below to pull the images in random order

    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );

    */

    // $active.addClass('last-active');

    next.css({opacity: 0.0})
        .addClass('show')
        .animate({opacity: 1.0}, 1000);
         current.animate({opacity: 0.0}, 1000) 
            .removeClass('show');

};

var thebackground = function ()
{
$('div.contain img').css(
{
    opacity: 0.0
});
$('div.contain img:first').css(
{
    opacity: 1.0
});
setInterval(function () {change()}, 5000);
}
 thebackground();
 $('div.contain').fadeIn(1000); // works for all the browsers other than IE
 $('div.contain img').fadeIn(1000); // IE tweak
});

这里的jFiddle演示:http://jsfiddle.net/LynchJustRules/g2tLn/6/