DiogoRedinDevelopment
DiogoRedinDevelopment Recent Posts Threads Started
572 posts
  • Located in Portugal
  • Contributed a blog post
  • Helped several times protecting Envato Market against copyright violations
  • Has sold $5,000+ on Envato Market
+4 more
DiogoRedinDevelopment 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
  • Has been part of the Envato Community for over 6 years
  • Has referred 10+ members
  • Has sold $40,000+ on Envato Market
  • Interviewed on an Envato blog
+11 more
JeffreyWay 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();
});
DiogoRedinDevelopment
DiogoRedinDevelopment Recent Posts Threads Started
572 posts
  • Located in Portugal
  • Contributed a blog post
  • Helped several times protecting Envato Market against copyright violations
  • Has sold $5,000+ on Envato Market
+4 more
DiogoRedinDevelopment 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…

DiogoRedinDevelopment
DiogoRedinDevelopment Recent Posts Threads Started
572 posts
  • Located in Portugal
  • Contributed a blog post
  • Helped several times protecting Envato Market against copyright violations
  • Has sold $5,000+ on Envato Market
+4 more
DiogoRedinDevelopment says

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

611 posts
  • Member of the Envato Team
  • Had an item featured in an Envato Bundle
  • Made it to the Authors' Hall of Fame
  • Contributed a blog post
+10 more
Siddharth Envato team 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();
});
DiogoRedinDevelopment
DiogoRedinDevelopment Recent Posts Threads Started
572 posts
  • Located in Portugal
  • Contributed a blog post
  • Helped several times protecting Envato Market against copyright violations
  • Has sold $5,000+ on Envato Market
+4 more
DiogoRedinDevelopment 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?

DiogoRedinDevelopment
DiogoRedinDevelopment Recent Posts Threads Started
572 posts
  • Located in Portugal
  • Contributed a blog post
  • Helped several times protecting Envato Market against copyright violations
  • Has sold $5,000+ on Envato Market
+4 more
DiogoRedinDevelopment 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 …

DiogoRedinDevelopment
DiogoRedinDevelopment Recent Posts Threads Started
572 posts
  • Located in Portugal
  • Contributed a blog post
  • Helped several times protecting Envato Market against copyright violations
  • Has sold $5,000+ on Envato Market
+4 more
DiogoRedinDevelopment says

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

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by