如何点击button切换图片

一共四个按钮,点第一个按钮出现图片一,点第二按钮出现图片二,点第三按钮出现图片三,点第四按钮出现图片四

img

img

这种效果可以吗?有帮助麻烦点个采纳【本回答右上角】,谢谢~~


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>jQuery带缩略图焦点图淡入淡切换特效</title>
    <style>
        /*Time for the CSS*/
        * {
            margin: 0;
            padding: 0;
        }

        body {
            background: #ccc;
        }

        .slider {
            width: 640px; /*Same as width of the large image*/
            position: relative;
            /*Instead of height we will use padding*/
            padding-bottom: 320px; /*That helps bring the labels down*/
            margin: 20px auto 100px auto;
            /*Lets add a shadow*/
            box-shadow: 0 10px 20px -5px rgba(0, 0, 0, 0.75);
        }

            /*Last thing remaining is to add transitions*/
            .slider > img {
                position: absolute;
                left: 0;
                top: 100px;
                transition: all 0.5s;
            }

            .slider input[name='slide_switch'] {
                display: none;
            }

            .slider label {
                /*Lets add some spacing for the thumbnails*/
                margin: 18px 0 0 18px;
                border: 3px solid #999;
                float: left;
                cursor: pointer;
                transition: all 0.5s;
                /*Default style = low opacity*/
                opacity: 0.6;
            }

                .slider label img {
                    display: block;
                }

                .slider label.focus {
                    border-color: #666;
                    opacity: 1;
                }
    </style>

</head>
<body>
    <div class="slider">
        <label class="focus">
            <img src="http://demo.lanrenzhijia.com/demo/50/5019/demo/images/3yiC6Yq.jpg" width="100" />
        </label>
        <label>
            <img src="http://demo.lanrenzhijia.com/demo/50/5019/demo/images/40Ly3VB.jpg" width="100" />
        </label>
        <label>
            <img src="http://demo.lanrenzhijia.com/demo/50/5019/demo/images/00kih8g.jpg" width="100" />
        </label>
        <label>
            <img src="http://demo.lanrenzhijia.com/demo/50/5019/demo/images/2rT2vdx.jpg" width="100" />
        </label>
        <label>
            <img src="http://demo.lanrenzhijia.com/demo/50/5019/demo/images/8k3N3EL.jpg" width="100" />
        </label>
        <img src="http://demo.lanrenzhijia.com/demo/50/5019/demo/images/3yiC6Yq.jpg" id="imgBig" />
    </div>
    <script src="https://g.csdnimg.cn/??lib/jquery/1.12.4/jquery.min.js"></script>
    <script>
        var imgs = $('.slider label img').click(function () {
            $('#imgBig').attr('src', this.src);
            imgs.parent().removeClass('focus'); this.parentNode.className = 'focus'
        })
    </script>
</body>
</html>


点击替换路径就行了呀

button绑定点击事件onclick(),在事件内修改图片的url

图片地址,放在一个数组里 。点击时 。切换 url和数组下标

换图片路径 和隐藏切换都可以的