Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

JS Slider not working

A project of mine (http://indiebundl.es) has some slider functionality that is not working properly...could anyone checkout the site (hit the 'Download Bundle' button) and see why these sliders are behaving crazily? Probably my own error.

Here's my code:

jQuery(document).ready(function () {
    function r(e) {
        t = $(e).val();
        n = Math.round(100 * (t / 3)) / 100;
        d = Math.round(100 * (n / 100)) / 100;
        $(".slider-charity").slider({
            value: n,
            max: t
        });
        $(".slider-value-charity").html("$" + d);
        $(".slider-artist").slider({
            value: n,
            max: t
        });
        $(".slider-value-artist").html("$" + d);
        $(".slider-ib").slider({
            value: n,
            max: t
        });
        $(".slider-value-ib").html("$" + d)
    }

    function o(e) {
        $(".filter ul").attr("data-type", e);
        var t = $(".filter ul .selected").html();
        $.post(i, {
            name: t,
            type: e
        }, function (e) {
            $(".bundle-container").empty();
            $(".bundle-container").append(e)
        })
    }

    function u(e) {
        $("html,body").animate({
            scrollTop: $(e).offset().top - 100
        }, "slow")
    }
    var e = "";
    $(".login").click(function () {
        $(".overlay").fadeIn();
        $("#login-modal").fadeIn()
    });
    $(".signup").click(function () {
        $(".overlay").fadeIn();
        $("#signup-modal").fadeIn()
    });
    $(".close-button").click(function () {
        var e = $(this).parent();
        $(".overlay").fadeOut();
        e.fadeOut()
    });
    $(".download-bundle").click(function () {
        $(".overlay").fadeIn();
        $("#download-modal").fadeIn();
        e = $(this).attr("data-bundle")
    });
    $(".link-group li").eq(1).click(function (e) {
        e.preventDefault();
        $(".overlay").fadeIn();
        $("#contact-modal").fadeIn()
    });
    $("#contact select").change(function () {
        $("#contact select option:selected").each(function () {
            if ($(this).text() === "Regular Message") {
                $(".contact-bug-report").fadeOut();
                $("#contact-modal").delay(250).animate({
                    height: 485
                }, 500, function () {
                    $(".contact-regular-message").delay(250).fadeIn()
                })
            } else if ($(this).text() === "Bug Report") {
                $(".contact-regular-message").fadeOut();
                $("#contact-modal").delay(250).animate({
                    height: 660
                }, 500, function () {
                    $(".contact-bug-report").delay(250).fadeIn()
                })
            }
        })
    });
    if (window.location.search.indexOf("status=thanks") > -1) {
        $(".overlay").fadeIn();
        $("#contact-thanks").fadeIn()
    }
    var t = 10,
        n = Math.round(100 * (t / 3)) / 100,
        d = Math.round(100 * (n / 100)) / 100;
    $("#a1").click(function () {
        r($(this))
    });
    $("#a2").click(function () {
        r($(this))
    });
    $("#a3").click(function () {
        r($(this))
    });
    $("#a4").click(function () {
        r($(this))
    });
    $(".slider-charity").slider({
        value: n,
        min: 0,
        max: t,
        step: .01,
        slide: function (e, n) {
            $(".slider-value-charity").html("$" + d);
            var r = Math.round(100 * ((t - n.value) / 2)) / 100;
            $(".slider-value-artist").html("$" + d);
            $(".slider-artist").slider("value", r);
            $(".slider-value-ib").html("$" + d);
            $(".slider-ib").slider("value", r);
            $(".split-options li").eq(3).siblings().removeClass("selected");
            $(".split-options li").eq(3).addClass("selected")
        }
    });
    $(".slider-value-charity").html("$" + $(".slider-charity").slider("value"));
    $(".slider-artist").slider({
        value: n,
        min: 0,
        max: t,
        step: 1,
        slide: function (e, n) {
            $(".slider-value-artist").html("$" + n.value);
            var r = Math.round(100 * ((t - n.value) / 2)) / 100;
            $(".slider-value-charity").html("$" + r);
            $(".slider-charity").slider("value", r);
            $(".slider-value-ib").html("$" + r);
            $(".slider-ib").slider("value", r);
            $(".split-options li").eq(3).siblings().removeClass("selected");
            $(".split-options li").eq(3).addClass("selected")
        }
    });
    $(".slider-value-artist").html("$" + $(".slider-artist").slider("value"));
    $(".slider-ib").slider({
        value: n,
        min: 0,
        max: t,
        step: 1,
        slide: function (e, n) {
            $(".slider-value-ib").html("$" + n.value);
            var r = Math.round(100 * ((t - n.value) / 2)) / 100;
            $(".slider-value-artist").html("$" + r);
            $(".slider-artist").slider("value", r);
            $(".slider-value-charity").html("$" + r);
            $(".slider-charity").slider("value", r);
            $(".split-options li").eq(3).siblings().removeClass("selected");
            $(".split-options li").eq(3).addClass("selected")
        }
    });
    $(".slider-value-ib").html("$" + $(".slider-ib").slider("value"));
    $(".split-options li").eq(0).click(function () {
        $(this).siblings().removeClass("selected");
        $(this).addClass("selected");
        $(".slider-charity").slider("value", n);
        $(".slider-value-charity").html("$" + n);
        $(".slider-artist").slider("value", n);
        $(".slider-value-artist").html("$" + n);
        $(".slider-ib").slider("value", n);
        $(".slider-value-ib").html("$" + n)
    });
    $(".split-options li").eq(1).click(function () {
        $(this).siblings().removeClass("selected");
        $(this).addClass("selected");
        $(".slider-charity").slider("value", t);
        $(".slider-value-charity").html("$" + t);
        $(".slider-artist").slider("value", 0);
        $(".slider-value-artist").html("$0");
        $(".slider-ib").slider("value", 0);
        $(".slider-value-ib").html("$0")
    });
    $(".split-options li").eq(2).click(function () {
        $(this).siblings().removeClass("selected");
        $(this).addClass("selected");
        $(".slider-charity").slider("value", 0);
        $(".slider-value-charity").html("$0");
        $(".slider-artist").slider("value", t);
        $(".slider-value-artist").html("$" + t);
        $(".slider-ib").slider("value", 0);
        $(".slider-value-ib").html("$0")
    });
    $(".split-options li").eq(3).click(function () {
        $(this).siblings().removeClass("selected");
        $(this).addClass("selected")
    });
    var i = "http://indiebundl.es/wp-content/themes/indiebundles/bundles.php",
        s = 0;
    $(".pay-button").click(function (t) {
        t.preventDefault();
        $("#download-modal").fadeOut();
        $(".overlay").fadeOut();
        var n = $(".slider-charity").slider("value"),
            r = $(".slider-artist").slider("value"),
            i = $(".slider-ib").slider("value"),
            s = $("input[name=value]:checked", "#download").val(),
            o = $("#download-promocode").val(),
            u = "http://indiebundl.es/wp-content/themes/indiebundles/charge.php",
            a = function (t) {
                var a = $("<input type=hidden name=stripeToken />").val(t.id),
                    f = a.val();
                $.post(u, {
                    bundle: e,
                    charity: n,
                    artist: r,
                    ib: i,
                    total: s,
                    promo: o,
                    stripeToken: f
                }, function (e) {
                    if (e !== "Query failed." || !e) {
                        $("#download-thanks").fadeIn();
                        $(".overlay").fadeIn();
                        setTimeout(function () {
                            window.location = e
                        }, 1e3)
                    } else {
                        $("#download-error").fadeIn();
                        $(".overlay").fadeIn()
                    }
                })
            }, f = "Checkout";
        if (o === "ROCKON") {
            s = 0;
            var f = "Free Download"
        }
        StripeCheckout.open({
            key: "############################",
            amount: s,
            currency: "usd",
            name: "Bundle",
            description: "A bundle",
            panelLabel: f,
            token: a
        });
        return !1
    });
    $(".filter ul li").click(function () {
        var e = $(this).parent().attr("data-type");
        $.post(i, {
            name: $(this).html(),
            type: e
        }, function (t) {
            if (e === "Artist") {
                $(".bundleartist-container").empty();
                $(".bundleartist-container").append(t)
            } else {
                $(".bundle-container").empty();
                $(".bundle-container").append(t)
            }
        });
        s = 0;
        $(this).siblings().removeClass("selected");
        $(this).addClass("selected")
    });
    $(".load-bundles").click(function () {
        var e = $(".filter ul .selected").html(),
            t = "Load";
        s += 3;
        e !== "Current" ? $.post(i, {
            name: e,
            type: t,
            offset: s
        }, function (e) {
            $(".bundleartist-container").append(e)
        }) : e === "Current" && $(".bundleartist-container").append('<p class="load-end">No more artists available</p>')
    });
    $(".view-box").click(function () {
        o("Box");
        $(this).siblings().removeClass("active");
        $(this).addClass("active")
    });
    $(".view-row").click(function () {
        o("Row");
        $(this).siblings().removeClass("active");
        $(this).addClass("active")
    });
    $(".anchor-container a").click(function () {
        u($(this).attr("href"))
    })
});

Make a reduced test case using codepen so we can see the issue you are having.

1 Answer

That page has over 9MB in images I'd hate to go that site on a 3G connection.