0

我无法让我的 jquery 图像滑块滚动到下一组图像。当我单击下一个箭头时,它不断将我带回页面顶部。我也不确定下一行图像是否设置正确。对不起,但我是使用 jquery 的新手。

html

<div id="wrapper2">
<label style="color: #5C5C5C;display: block; font-weight: bold; font-size:16px; text-align: center;margin-bottom:0px;padding-bottom:20px;">Reaching our Goal is proud to partner with great organizations</label>
        <div id="thumbs-wrapper2">
            <div id="thumbs">
                <a class="selected" href="#2"><img src="/assets/images/ROG_p.jpg" /></a>
                <a href="#"><img src="/assets/images/gametime_p.jpg" /></a>
                <a href="#"><img src="/assets/images/american_p.jpg" /></a>
                <a href="#"><img src="/assets/images/bfs_p.jpg" /></a>
                <a href="#"><img src="/assets/images/vballfestival_p.jpg" /></a>
                <a href="#"><img src="/assets/images/yfbca_p.jpg" /></a>
                <a href="#"><img src="/assets/images/sportsattack_p.jpg" /></a>
                <a href="#"><img src="/assets/images/ROG_p.jpg" /></a>
                <a href="#"><img src="/assets/images/gametime_p.jpg" /></a>
                <a href="#"><img src="/assets/images/american_p.jpg" /></a>
                <a href="#"><img src="/assets/images/bfs_p.jpg" /></a>
                <a href="#"><img src="/assets/images/vballfestival_p.jpg" /></a>
                <a href="#"><img src="/assets/images/yfbca_p.jpg" /></a>
                <a href="#"><img src="/assets/images/sportsattack_p.jpg" /></a>
            </div>
            <a id="prev" href="#"></a>
            <a id="next" href="#"></a>
        </div>
</div>

脚本

$('#thumbs').carouFredSel({
        responsive: true,
        auto: true,
        prev: '#prev',
        next: '#next',
        items: {
            visible: 
             min: 2,
             max: 4
            },
            width: 150,
            height: '25%'
    });
    });

    $('#thumbs a').click(function() {
        $('#carousel').trigger('slideTo', '#'+this.href.split('#').pop());
        $('#thumbs a').removeClass('selected');
        $(this).addClass('selected');
        return false;
    });

css

#wrapper2 {
    position: relative;
    width: 100%;
    top: 50px;
}
#carousel, #thumbs {
    overflow: hidden;
    height: 62px;
}

#carousel span, #carousel img,
#thumbs a, #thumbs img  {
    display: block;
    float: left;
}
#carousel span, #carousel a,
#thumbs span, #thumbs a {
    position: relative;
}
#carousel img,
#thumbs img {
    border: medium none;
    height: 58px;
    left: 0;
    position: relative;
    top: 0;
    width: 100px;
}
#carousel img.glare,
#thumbs img.glare {
    width: 102%;
    height: auto;
}

#thumbs-wrapper2 {
    padding: 20px 40px;
    position: relative;
    width: 73%;
    margin: -18px 0 0 162px;
    height: 90px;
}
#thumbs a {
    height: 58px;
    margin: 0 10px;
    overflow: hidden;
    width: 100px;
    border: 2px solid #899;
    border-radius: 10px;
    -webkit-transition: border-color .5s;
    -moz-transition: border-color .5s;
    -ms-transition: border-color .5s;
    transition: border-color .5s;

}
#thumbs a:hover, #thumbs a.selected {
    border-color: #566;
}

#prev, #next {
    display: block;
    height: 50px;
    margin: -38px 0 0 -35px;
    position: absolute;
    top: 50%;
    width: 50px;
}
#prev {
    background-image: url(/assets/images/left.jpg);
    background-position: 0 0;
    left: 10px;
}
#next {
    background-image: url(/assets/images/right.jpg);
    background-position: -50px 0;
    right: 33px;
}           
#prev:hover { 
    background-position: 0 0;               
}
#next:hover {
    background-position: -50px 0;               
}

#prev.disabled, #next.disabled {
    display: none !important;
}
4

2 回答 2

0

href="#"你的下一个和上一个标签中导致它。删除它们或将其更改为href="javascript:void(0)"

于 2012-05-15T01:14:34.767 回答
0

确保您的 javascript 在 html 下方,或使用$(function()

$(function() {
   $('#thumbs').carouFredSel({
        responsive: true,
        auto: true,
        prev: '#prev',
        next: '#next',
        items: {
            visible: 
             min: 2,
             max: 4
            },
            width: 150,
            height: '25%'
    });
    });

    $('#thumbs a').click(function() {
        $('#carousel').trigger('slideTo', '#'+this.href.split('#').pop());
        $('#thumbs a').removeClass('selected');
        $(this).addClass('selected');
        return false;
    });
});

#此外,大多数浏览器的默认行为是在看到in时将您带到页面顶部,您可以通过调用传入的对象href来告诉它停止该行为.preventDefault()eventclick()

$('#thumbs a').click(function(e) {
    e.preventDefault(); // add this
    $('#carousel').trigger('slideTo', '#'+this.href.split('#').pop());
    $('#thumbs a').removeClass('selected');
    $(this).addClass('selected');
    return false;
});

编辑:问题是由语法错误引起的:

$('#thumbs').carouFredSel({
        responsive: true,
        auto: true,
        prev: '#prev',
        next: '#next',
        items: {
            visible: // here you forgot to assign anything to visible
             min: 2,
             max: 7
于 2012-05-15T01:15:02.410 回答