I have a slide gallery which adds a class curSlide
to an image when it is being displayed within the gallery.
I have divs containing text corresponding to the slides within the gallery, ie. #group2-text
should be displayed when a .group2-img
has the class curSlide
. Both gallery-text divs are set as display: none
within the css. Is it possible to get jquery to display the correct div depending upon the curSlide
class?
html:
<div class="page-content" id="projects-commercial-content">
<div class="gallery" id="projects-commercial-gallery">
<div class="gallery-holder">
<div id="projects-commercial-slides" class="slides">
<img id="comm1" src="images/commercial1.jpg" class="slide-image group1-img" alt=""/>
<img id="comm2" src="images/commercial2.jpg" class="slide-image开发者_StackOverflow社区 group1-img" alt=""/>
<img id="comm3" src="images/commercial3.jpg" class="slide-image group1-img" alt=""/>
<img id="comm4" src="images/commercial4.jpg" class="slide-image group2-img" alt=""/>
<img id="comm5" src="images/commercial5.jpg" class="slide-image group2-img" alt=""/>
<img id="comm6" src="images/commercial6.jpg" class="slide-image group2-img" alt=""/>
</div>
</div><!--gallery-holder-->
<div class="gallery-text" id="group1-text">
<h3>project <span class="abbrev">group 1</span></h3>
<p>Group 1 description text. Suspendisse ultricies molestie nisi id bibendum. Mauris bibendum ipsum at massa malesuada eu venenatis velit pretium.</p>
</div>
<div class="gallery-text" id="group2-text">
<h3>project <span class="abbrev">group 2</span></h3>
<p>Group 2 description text etc. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse imperdiet justo ac ligula congue posuere. Aliquam erat volutpat </p>
</div><!--gallery-text-->
</div><!--gallery-->
</div><!--page-content-->
The part of the gallery js adding the class is here:
_fade: function (navigateData) {
// put hidden to slide above current
this.slides.eq( navigateData.to ).addClass('curSlide').css({
zIndex: 10
// fade in next
}).fadeIn(this.options.fade.interval, this.options.fade.easing, $.proxy(function(){
// hide previous
navigateData.currentSlide.removeClass('curSlide').css({
display: "none",
zIndex: 0
});
// reset zindex
this.slides.eq( navigateData.to ).css({
zIndex: 0
});
this.current = navigateData.to;
this._trigger("navigateEnd", ( this.current + 1 ), this);
}, this));
},
I didn't write the gallery js and I'm not really sure how to adapt it to display the corresponding div/text.
Any help is much appreciated! Please let me know if more details are required. TIA!
I haven't tested this, but give it a try. Modify the part of the gallery script
_fade: function (navigateData) {
//hide text and show new text
$('.gallery-text').css('display','none');
var curImgClass = $(this.slides.eq( navigateData.to )).attr('rel');
$('#' + curImgClass + '-text').css('display','block');
// put hidden to slide above current
this.slides.eq( navigateData.to ).addClass('curSlide').css({
zIndex: 10
// fade in next
}).fadeIn(this.options.fade.interval, this.options.fade.easing, $.proxy(function(){
// hide previous
navigateData.currentSlide.removeClass('curSlide').css({
display: "none",
zIndex: 0
});
// reset zindex
this.slides.eq( navigateData.to ).css({
zIndex: 0
});
this.current = navigateData.to;
this._trigger("navigateEnd", ( this.current + 1 ), this);
}, this));
},
You can try this idea, unfortunately cannot test:
HTML code modified:
<div class="page-content" id="projects-commercial-content">
<div class="gallery" id="projects-commercial-gallery">
<div class="gallery-holder">
<div id="projects-commercial-slides" class="slides">
<img id="comm1" src="images/commercial1.jpg" class="slide-image" alt="" rel="group1"/>
<img id="comm2" src="images/commercial2.jpg" class="slide-image group1-img" rel="group1" alt=""/>
<img id="comm3" src="images/commercial3.jpg" class="slide-image group1-img" rel="group1" alt=""/>
<img id="comm4" src="images/commercial4.jpg" class="slide-image" rel="group2" alt=""/>
<img id="comm5" src="images/commercial5.jpg" class="slide-image" rel="group2"alt=""/>
<img id="comm6" src="images/commercial6.jpg" class="slide-image" rel="group2" alt=""/>
</div>
</div><!--gallery-holder-->
<div class="gallery-text" id="group1">
<h3>project <span class="abbrev">group 1</span></h3>
<p>Group 1 description text. Suspendisse ultricies molestie nisi id bibendum. Mauris bibendum ipsum at massa malesuada eu venenatis velit pretium.</p>
</div>
<div class="gallery-text" id="group2">
<h3>project <span class="abbrev">group 2</span></h3>
<p>Group 2 description text etc. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse imperdiet justo ac ligula congue posuere. Aliquam erat volutpat </p>
</div><!--gallery-text-->
</div><!--gallery-->
</div><!--page-content-->
JS piece of code:
_fade: function (navigateData) {
// put hidden to slide above current
$(".gallery-text").hide();
this.slides.eq( navigateData.to ).addClass('curSlide').css({
zIndex: 10
// fade in next
}).fadeIn(this.options.fade.interval, this.options.fade.easing, $.proxy(function(){
// hide previous
var detElement = this.getAttribute('rel');
$(".gallery-text[rel="+detElement+"]").fadeIn();
navigateData.currentSlide.removeClass('curSlide').css({
display: "none",
zIndex: 0
});
// reset zindex
this.slides.eq( navigateData.to ).css({
zIndex: 0
});
this.current = navigateData.to;
this._trigger("navigateEnd", ( this.current + 1 ), this);
}, this));
精彩评论