码迷,mamicode.com
首页 > 其他好文 > 详细

如何实现点击左右按钮换图片?

时间:2015-08-05 14:40:03      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:

<div class="login_box" id="wrapper">
<a onclick="leftCheck()" class="image_left"></a>
<a id="image_right" onclick="rightCheck()" class="image_right"></a>
<div id="imageContainer">
<img src="../img/LoginIndexImg1.jpg" class="active" />
<img src="../img/LoginIndexImg2.jpg" />
<img src="../img/LoginIndexImg3.jpg" />
</div>
</div>

 

/ 登录页背景图切换
var imageObject = {
    clickSwap : function(obj) {
        obj.click(function() {
            var activeImage = $(this).children(‘img.active‘);
            activeImage.removeClass(‘active‘);
            if (activeImage.next().length > 0) {
                activeImage.next().addClass(‘active‘);
            } else {
                $(this).children(‘img:first-child‘).addClass(‘active‘);
            }
            return false;
        });
    }
};
function leftCheck(){

            var activeImage = $(‘.active‘);
            activeImage.removeClass(‘active‘);
            if (activeImage.prev().length > 0) {
                activeImage.prev().addClass(‘active‘);
            } else{
                $("#imageContainer").children(‘img:last-child‘).addClass(‘active‘);
                //activeImage.next().addClass(‘active‘);
            }




};
function rightCheck(){
            var activeImage = $(‘.active‘);
            activeImage.removeClass(‘active‘);
            if (activeImage.next().length > 0) {
                activeImage.next().addClass(‘active‘);
            }else{
                $("#imageContainer").children(‘img:first-child‘).addClass(‘active‘);
                //activeImage.prev().addClass(‘active‘);
            }
            

};

 

如何实现点击左右按钮换图片?

标签:

原文地址:http://www.cnblogs.com/master-zxc/p/4704568.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!