0

Just wondered if this code could be optomiosed in anyway? It works great, just wanted to make sure there weren't any ways to simplify this or if there are any obvious errors in the markup. Asking primerly because of that second call in the first function, not sure if it's needed?

$(document).on("click", '.load', function (event) {
    var $projects = $("#projects"),
        id = $(this).data('id');
    $projects.html("").data('id', id);
    $("#loading").show();
    $projects.load("projects.html #div" + id, function () {
        $("#projects").show();
        $("#loading").hide();
    })
});

$(document).on("click", '.next', function (event) {
    var $projects = $("#projects");
    pid = $projects.data('id');
    $projects.data('id', (pid == 6) ? 1 : (pid + 1));
    $projects.load("projects.html #div" + $projects.data('id'));
});


$(document).on("click", '.previous', function (event) {
    var $projects = $("#projects");
    pid = $projects.data('id');
    $projects.data('id', (pid == 1) ? 6 : (pid - 1));
    $projects.load("projects.html #div" + $projects.data('id'));
});

$(document).on("click", '.exit', function (event) {
    $("#projects").hide();
});
2
Contributors
4
Replies
19
Views
3 Years
Discussion Span
Last Post by Mr.Pink
0

Mind showing me how to do that? I don't really see how that's possible with it replying on click classes?

0

Here's a start:

function loadProject(var next) {
    var $projects = $("#projects");
    pid = $projects.data('id');

    if (next) {
        pid = (pid == 6) ? 1 : (pid + 1);
    }
    else {
        pid = (pid == 1) ? 6 : (pid - 1);
    }

    $projects.data('id', pid);
    $projects.load("projects.html #div" + pid);
}

$(document).on("click", '.next', function (event) {
    loadProject(true);
});

$(document).on("click", '.previous', function (event) {
    loadProject(false);
});
0

Just given that a go and having a hard time getting anyting to work if I'm honest.

I'm getting an error on this line function loadProject(var next) {

Is that just because It's rough code or am I missing something?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.