Jump to content

[SOLVED] help adding links to this jquery/javascript code


CyberShot

Recommended Posts

I have downloaded a script for pagination. I have it up and running fine. You can view it here

 

http://www.creativeeventsdesign.com/orange/portfolio.html

 

if you click the number links on the bottom of the page, it will change the page and add four new blocks, I have titled these

 

photo, site, car, homes, and building. Just for testing.

 

On the right, I have a menu titled "Categories". What I would like is that you could click on the category and it will take you to that page in the pagination. I tried using named anchor links but it doesn't work. I do not know javascript. Can you help

 


$(document).ready(function(){

    var show_per_page = 4; //set the number of blocks to show
    var number_of_items = $('#pagination').children().size();
    var number_of_pages = Math.ceil(number_of_items/show_per_page);
    var end = number_of_pages -1;

    $('#current_page').val(0);
    $('#show_per_page').val(show_per_page);

    var navigation_html = '<a href="javascript:go_to_page(0);">Begin</a>';
    navigation_html += '<a href="javascript:nav(-1);">Prev</a>';
    var current_link = 0;
    while(number_of_pages > current_link){
        navigation_html += '<a class="page_link" href="javascript:go_to_page(' + current_link +')" longdesc="' + current_link +'">'+ (current_link + 1) +'</a>';
        current_link++;
    }
    navigation_html += '<a href="javascript:nav(+1);">Next</a>';
    navigation_html += '<a href="javascript:go_to_page(' + end +')"">End</a>';

    $('#page_navigation').html(navigation_html);
    $('#page_navigation .page_link:first').addClass('active_page');

    $('#pagination').children().css('display', 'none');
    $('#pagination').children().slice(0, show_per_page).css('display', 'block');

});

function nav(dir){
    if(dir==+1){
        new_page = parseInt($('#current_page').val()) + 1;
        if($('.active_page').next('.page_link').length==true){
            go_to_page(new_page);
        }
    }else if(dir==-1){
        new_page = parseInt($('#current_page').val()) - 1;
        if($('.active_page').prev('.page_link').length==true){
            go_to_page(new_page);
        }
    }
}

function go_to_page(page_num){
    var show_per_page = parseInt($('#show_per_page').val());
    start_from = page_num * show_per_page;
    end_on = start_from + show_per_page;
    $('#pagination').children().css('display', 'none').slice(start_from, end_on).css('display', 'block');
    $('.page_link[longdesc=' + page_num +']').addClass('active_page').siblings('.active_page').removeClass('active_page');
    $('#current_page').val(page_num);
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.