Separate the arrows from the slider functionalities

时间:2015-06-26 09:52:36

标签: javascript jquery html css

I have this slider that's switching dividers, and above it two arrows (prev and next) now i don't care about the way the arrows look or the way they are positioned. But i want them functional, however other functionalities applied to the slider such as hover, is being applied to the arrows too. How can i keep the buttons function (next/prev) but make it separate from the slider.

JSFIDDLE: http://jsfiddle.net/1ju1k0f6/

CSS:

#first
{   
    width: 50%;
    height: 220px;
    margin:auto;
    padding-left: 170px;
    margin-top: 2px;

}
#first img 
{
     height: 100px;
    width: 100px;
    float:left;
    margin-right: 5%;
    cursor: pointer;
}

#wrapper {
    width: 10%;
    padding: px 0;

}

#slider-container {
    padding: 20px 50px;
    height: 1350px;
    top:-18%;
    left: -45px;
    width: 700px;
    overflow: hidden;
    position: relative;
}

.slider-view-area {

    max-height: 300px;

}

#nav img {
    position: absolute;
    top: 40px;
    left: 0px;
    cursor:pointer;
    color:grey;


}
#prev {
    margin-left: 520px;
    font-size: 30px;
}
#next {
    right: -440px;
    font-size: 30px;
}

#mask {
    width: 5000px;
    height: 100%;

}

.item {
    width: 1200px;
    height: 100%;
    float: left;

}
.content img {
    height: 100px;
    width: 17%;
    float:left;
    margin-right:  10px;
    margin-bottom: 10px;
    cursor: pointer;
}
.content {
    width: 50%;
    height: 220px;
    top: 30px;
    left: 
    margin: auto;

    position: relative;
}
.content a {
    position: relative;
    top: -17px;
    left: 170px;
}
.selected {
    background: #fff;
    font-weight: 700;
}
.clear {
    clear:both;
}

.hidden {
    display: none;
}

2 个答案:

答案 0 :(得分:2)

You can be more specific in your selectors targetting only img elements within the div with class .slider-view-area

jQuery(function ($) {
    $('.slider-view-area img').hover(function () { // on mouseover
        $('.slider-view-area img').stop().not(this).animate({
            'opacity': 0.4
        }, 700); // you can animate this as well
        $(this).animate({
            'opacity': 1
        }, 700);
    }, function () { // on mouseout
        $('#.slider-view-area img').animate({
            'opacity': 1
        }, 700);
    });
});

Demo:http://jsfiddle.net/1ju1k0f6/1/

答案 1 :(得分:0)

Add another .not filter to your code, change :

$('#first img').stop().not(this).animate({'opacity':0.4},700); // you can animate this as well

to

 $('#first img').stop().not(this).not('#prev, #next').animate({'opacity':0.4},700); // you can animate this as well

jsfiddle