最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Advanced Captions with bxslider - Stack Overflow

programmeradmin4浏览0评论

This question has already been asked, but has no answer - I believe because not enough information was provided.

I am using the bxslider as my template. See here:

I can create a very simply caption using the "title" attribute, but I want to be able to create subtitles (with different attributes like smaller text) and I want to turn this into a link. I've tried implementing a div within the container, and perhaps obviously, I can't get that to sync with the slider without implementing it with jquery. I've also tried editing the CSS to no avail.

How can I add a caption that more than just an image title? Like a div overlaying the picture?

This question has already been asked, but has no answer - I believe because not enough information was provided.

I am using the bxslider as my template. See here: http://bxslider./examples/image-slideshow-captions

I can create a very simply caption using the "title" attribute, but I want to be able to create subtitles (with different attributes like smaller text) and I want to turn this into a link. I've tried implementing a div within the container, and perhaps obviously, I can't get that to sync with the slider without implementing it with jquery. I've also tried editing the CSS to no avail.

How can I add a caption that more than just an image title? Like a div overlaying the picture?

Share Improve this question edited Nov 6, 2015 at 11:13 RandomPleb asked Feb 15, 2014 at 5:26 RandomPlebRandomPleb 4241 gold badge5 silver badges20 bronze badges 3
  • Your fiddle doesn't work... – ITChristian Commented Feb 15, 2014 at 5:38
  • I'm just using that to share ALL of the code. There's quite a bit. I don't know how to get that fiddle to work. It's working on my website though. – RandomPleb Commented Feb 15, 2014 at 5:47
  • @RandomPleb, I believe both the answers should work. Try them out and let us know where you are facing problems. – VJS Commented Feb 15, 2014 at 6:06
Add a ment  | 

2 Answers 2

Reset to default 12

You don't even need to use the captions option provided by bxslider. Add the captions as part of the li tag that forms your slide. That's what the captions:true option does anyways, i.e appends the div with bx-caption class to your slide.

For eg:

  <li>
      <img src="http://bxslider./images/730_200/hill_trees.jpg" />
      <div class="caption1"> 
        <span>Image 1</span>
        <div class="caption2"><a id="img1a" href="#">Visit Australia</a></div>
      </div>
 </li>

This way using css, you can play around with the font sizes too.

Here's the the fiddle http://jsfiddle/s2L9P/

I think I solved your problem, but I can't test it because your fiddle doesn't work as you created it.

Change the code from Appends image captions to the DOM with this:

    /**
     * Appends image captions to the DOM
     * NETCreator enhancement (http://wwwcreator.ro)
     */
    var appendCaptions = function(){
        // cycle through each child
        slider.children.each(function(index){
            // get the image title attribute
            var title = $(this).find('img:first').attr('title');
            var nc_subtitle = $(this).find('img:first').attr('nc-subtitle');
            // append the caption
            if (title != undefined && ('' + title).length && nc_subtitle != undefined && ('' + nc_subtitle).length) {
                $(this).append('<div class="bx-caption"><span class="title">' + title + '</span><br/><span class="nc_subtitle">' + nc_subtitle + '</span></div>');
            }
        });
    }

Now you can add subtitles to your caption titles:

<a href ="page.php">
    <img src="http://calindragan.files.wordpress./2011/01/winter.jpg" title="title 1 here" nc-subtitle="The second title"/>
</a>

You can style the subtitle as you want to, using the CSS class nc_subtitle.

Hope it helps!

EDIT

Change the entire JavaScript shared by you in fiddle with this:

http://pastebin./0fvUezg1

And the HTML with this:

http://pastebin./T038drDV

It works.

发布评论

评论列表(0)

  1. 暂无评论