542 posts
  • Exclusive Author
  • Europe
  • Sold between 5 000 and 10 000 dollars
  • Has been a member for 3-4 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Contributed a Blog Post
  • Bought between 10 and 49 items
  • Referred between 1 and 9 users
ThemesFever says

Hi there!

I’m trying to make the content page to only appear when the user clicks on a button. I’m doing it with jQuery.

The problem is that the content page uses a jQuery scroll bar, and when I load the content page using jQuery, the scroll bar doesn’t work.

Here is the HTML / PHP code:

    <!--Show page button-->
    <a href="#" class="show_page">
        &lt;?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?&gt;
            &lt;?php the_title(); ?&gt;
        &lt;?php endwhile; ?&gt;
    </a>
    <!--Show page button-->

    <!--Home page Content-->
    <div id="page_content">
        &lt;?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?&gt;

            <div id="the_title">
                &lt;?php the_title(); ?&gt;
            </div>

            <div class="scroll-pane">
                <div id="the_content">
                    &lt;?php the_content(); ?&gt;
                </div>
            </div>

        &lt;?php endwhile; ?&gt;
    </div>
    <!--Ends Home Page content-->

The div “scroll-pane” adds a scroll bar to the content. This scroll bar doesn’t work when I load the content page with jQuery.

Here is the jQuery code:

$(document).ready(function(){

// Hide The Page Content
$("#page_content").hide();

$(".show_page").click(function(){
    // Show the page content
    $('#page_content').show();

    // Hide the top show button
    $(".show_page").hide();
});

});

Am I doing something wrong? Thank you :bigsmile:

2529 posts
  • Attended a Community Meetup
  • Author had a Free File of the Month
  • Blog Editor
  • Bought between 50 and 99 items
  • Contributed a Tutorial to a Tuts+ Site
  • Envato Staff
  • Exclusive Author
+8 more
JeffreyWay Moderator says

Seems to be working for me.

http://jsfiddle.net/EApdn/

On a side note, you’ll want to clean up the jQuery code a bit. You’re creating extra jQuery objects for no reason. This is better:

$(document).ready(function(){

   var = page_content = $('#page_content').hide(),
           show_page = $('a.show_page');

show_page.click(function(e) {
  page_content.show();
  show_page.hide();
  e.preventDefault();
});
542 posts
  • Exclusive Author
  • Europe
  • Sold between 5 000 and 10 000 dollars
  • Has been a member for 3-4 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Contributed a Blog Post
  • Bought between 10 and 49 items
  • Referred between 1 and 9 users
ThemesFever says
JeffreyWay said
Seems to be working for me. http://jsfiddle.net/EApdn/

On a side note, you’ll want to clean up the jQuery code a bit. You’re creating extra jQuery objects for no reason. This is better:

$(document).ready(function(){

   var = page_content = $('#page_content').hide(),
           show_page = $('a.show_page');

show_page.click(function(e) {
  page_content.show();
  show_page.hide();
  e.preventDefault();
});

Thank you for the help! Really appreciate it :) But the problem persists. I will try to explain better:

The script you wrote works fine, but the problem is that the page content is using a jQuery scroll bar script (http://jscrollpane.kelvinluck.com/), that doesn’t work when the page content is shown using jQuery.

I really don’t know if anyone can help me, because it seems to be a difficult bug to solve :(

Maybe I can show the page content using other techniques…

542 posts
  • Exclusive Author
  • Europe
  • Sold between 5 000 and 10 000 dollars
  • Has been a member for 3-4 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Contributed a Blog Post
  • Bought between 10 and 49 items
  • Referred between 1 and 9 users
ThemesFever says

I think I found the solution :bigsmile: I will post it here tomorrow!

606 posts
  • Envato Staff
  • Blog Editor
  • Senior Reviewer
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Author had a File in an Envato Bundle
  • Forum Moderator
  • Microlancer Beta Tester
  • Sold between 10 000 and 50 000 dollars
+9 more
Siddharth Staff says

This should work. The issue is probably with the plugin instantiation and without the full code, it’s hard to pin point the source.

But I’m guessing this is similar to Cufon where elements added dynamically after DOM ready are unstyled and in our case, without a styled scroll bar.

$(document).ready(function(){

   var pageContent = $('#page_content').hide(),
        showPage = $('a.show_page');

showPage.click(function(e) {
  pageContent.show().jScrollPane();
  showPage.hide();
  e.preventDefault();
});
542 posts
  • Exclusive Author
  • Europe
  • Sold between 5 000 and 10 000 dollars
  • Has been a member for 3-4 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Contributed a Blog Post
  • Bought between 10 and 49 items
  • Referred between 1 and 9 users
ThemesFever says
Siddharth said
This should work. The issue is probably with the plugin instantiation and without the full code, it’s hard to pin point the source.

But I’m guessing this is similar to Cufon where elements added dynamically after DOM ready are unstyled and in our case, without a styled scroll bar.

$(document).ready(function(){

   var pageContent = $('#page_content').hide(),
        showPage = $('a.show_page');

showPage.click(function(e) {
  pageContent.show().jScrollPane();
  showPage.hide();
  e.preventDefault();
});

Thank you Siddharth! I can now see the scroll bar, but the CSS styles aren’t working correctly. Any thoughts on this?

542 posts
  • Exclusive Author
  • Europe
  • Sold between 5 000 and 10 000 dollars
  • Has been a member for 3-4 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Contributed a Blog Post
  • Bought between 10 and 49 items
  • Referred between 1 and 9 users
ThemesFever says

This is how the page is styled:

This is how the page looks like when is loaded using jQuery:

The page is loading first jQuery, then the code we are using to show the page content and then the scroll bar script.

I really don’t know what is wrong with this …

542 posts
  • Exclusive Author
  • Europe
  • Sold between 5 000 and 10 000 dollars
  • Has been a member for 3-4 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Contributed a Blog Post
  • Bought between 10 and 49 items
  • Referred between 1 and 9 users
ThemesFever says

The problem is now solved :bigsmile: Thank you both!

by
by
by
by
by
by