Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Why doesn't a single JQuery-based content slider work for me? (bxSlider, commas in js)

Why doesn't a single JQuery-based content slider work for me? (bxSlider, commas in js)

Problem

I've been trying to incorporate a JQuery-based content Slider on my website for a long time now, but I haven't been able to get a single one to work. Here is the relevant bit of code in the webpage's php:

    '; echo $poem['Poem']; echo ''; $totalElements++; } $currentElement = $poem['ID']; ?>

Notice that it pulls paragraphs from a MySQL database to add content slides to the bxSlider. And yet, I get this result: enter image description here

That is the two entries of the table laid on top of one another, in the fashion of a normal unordered list. So it's not applying the actual slider.

Just to be sure, I tried a regular list instead of having fancy mysql stuff. No luck there, either: enter image description here

It's not just BxSlider. LightSlider and (I think) Jssor Slider haven't worked for me either. Something that's been happening pretty consistently is this error: enter image description here

That error manifests itself as "unexpected token ," half the time, and most of the time, completely breaks my javascript. And it comes up every time I use commas in my javascript code for some crazy reason, which means it's only okay with me using:

$('.bxslider').bxslider();

Which is okay, except that that doesn't let me customize the slider(along with it already not working to begin with). Even lightSlider demands the same thing:

var slider = $('#publicMethods').lightSlider({
    slideMargin:4,
    slideWidth:200,
    loop:false
});

I've tried both these sliders with and without their included css files.

So, what the heck?

Sorry that my first question here is so vague. I hope the scope of it isn't huge. This is my first major web project. But if it helps, I've added the sourcecode of the entire project sans database info to the reference txt by way of pastebin.

The ultimate goal is for it to show only one paragraph at a time, and for the user to be able to click buttons or swipe to read each paragraph in order from the table.

Pastebin 1 (PHP/HTML): http://pastebin.com/6uY77hC2
Pastebin 2 (CSS): http://pastebin.com/jh9AFLpJ
Pastebin 3 (JS): http://pastebin.com/TPXbBZR6

Problem courtesy of: Tilde White

Solution

There is a typo in your selector name , in html class name is class="bxSlider" (S is caps) but in Js you are using $('.bxslider') (s is small) , thats why in your JS it is not selecting the element correctly and your slider is not created.

Also note, the function name is bxSlider() not bxslider() (again typo).

Updated your JS fiddle and its working now http://jsfiddle.net/c1kqeLt4/3/

$('.bxSlider').bxSlider({
    adaptiveHeight: true,
    minSlides: 1,
    maxSlides: 1,
    slideWidth: 100
});

For css part, it is not working because Bxslider adds style 'float:left' on

  • , so height of ul becomes zero. Give background on
  • and it will work.

    Updated JS fiddle demo: http://jsfiddle.net/c1kqeLt4/7

    Solution courtesy of: Sanjeev
  • Discussion

    View additional discussion.



    This post first appeared on CSS3 Recipes - The Solution To All Your Style Problems, please read the originial post: here

    Share the post

    Why doesn't a single JQuery-based content slider work for me? (bxSlider, commas in js)

    ×

    Subscribe to Css3 Recipes - The Solution To All Your Style Problems

    Get updates delivered right to your inbox!

    Thank you for your subscription

    ×