WordPress.org

Ready to get started?Download WordPress

Forums

Javascript Scroll bar in post (13 posts)

  1. someguy03
    Member
    Posted 3 years ago #

    I am trying to integrate this into a wordpress post:

    http://www.n-son.com/scripts/jsScrolling/example4.html

    It's a very minimalistic corporate site with fixed dimensions so they want a scroll bar on the text.

    I put the javascript call in the header as instructed:

    <script type="text/javascript" src="src/jsScroller.js"></script>
    <script type="text/javascript" src="src/jsScrollbar.js"></script>

    I also tried putting the script and the CSS in the post, and the text/css loads, but the javascript does not. Any help?

  2. In header.php, try the full path to your copies of those two scripts.

  3. someguy03
    Member
    Posted 3 years ago #

    Thanks for the help, here's a portion of my header, is this correct?

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    
    <head>
    
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <script type="text/javascript" src="http://kylefoleydesign.com/rbfgroup/css/jsScrollbar.js"></script>
    <script type="text/javascript" src="http://kylefoleydesign.com/rbfgroup/css/jsscroller.js"></script>
    
    <title><?php bloginfo('name'); ?>: <?php bloginfo('description'); ?> <?php wp_title(); ?></title>
  4. Does it work? Does Firebug show the JS loading OK?

  5. someguy03
    Member
    Posted 3 years ago #

    No, it is not working. The Firebug console just says:

    syntax error
    [Break on this error] var scrollbar = null;</p>\n

    Here's the code I have for the post. For testing purposes I extracted it right from that example I posted earlier:

    <style type="text/css">
    .Scroller-Container {
    
    }
    .Scrollbar-Up {
      position: absolute;
      width: 10px; height: 10px;
      background-color: #CCC;
      font-size: 0px;
    }
    .Scrollbar-Track {
      width: 10px; height: 160px;
      position: absolute;
      top: 20px;
      background-color: #EEE;
    }
    .Scrollbar-Handle {
      position: absolute;
      width: 10px; height: 30px;
      background-color: #CCC;
    }
    .Scrollbar-Down {
      position: absolute;
      top: 190px;
      width: 10px; height: 10px;
      background-color: #CCC;
      font-size: 0px;
    }
    #Scrollbar-Container {
      position: absolute;
      top: 50px; left: 460px;
    }
    
    #Container {
      position: absolute;
      top: 50px; left: 50px;
      width: 400px;
      height: 200px;
      background-color: #EEE;
    }
    #News, #About, #Extra {
      position: absolute;
      top: 10px;
      overflow: hidden;
      width: 400px;
      height: 180px;
      display: none;
    }
    #News {display: block;}
    p {
      margin: 0; padding: 0px 20px 10px;
      font-family: Verdana, Arial, Helvetica, sans-serif;
      font-size: 11px;
      text-indent: 20px;
      color: #777;
    }
    #Navigation {
      position: absolute;
      top: 30px;
      left: 75px;
    }
    #Navigation a {
      margin: 5px 2px 0 0;
      padding: 0 5px;
      height: 20px;
      background-color: #E4E4E4;
      font-family: Verdana, Arial, Helvetica, sans-serif;
      font-size: 10px;
      color: #AAA;
      text-decoration: none;
      display: block;
      float: left;
      letter-spacing: 1px;
    }
    #Navigation a:hover {
      margin-top: 0px;
      height: 25px;
    }
    #Navigation a.current {
      margin-top: 0px;
      height: 25px;
      background-color: #EEE;
      color: #777;
    }
    </style>
    <script type="text/javascript">
    var scroller  = null;
    var scrollbar = null;
    
    window.onload = function () {
      scroller  = new jsScroller(document.getElementById("News"), 400, 180);
      scrollbar = new jsScrollbar (document.getElementById("Scrollbar-Container"), scroller, true, scrollbarEvent);
    }
    
    function scrollbarEvent (o, type) {
    	if (type == "mousedown") {
    		if (o.className == "Scrollbar-Track") o.style.backgroundColor = "#E3E3E3";
    		else o.style.backgroundColor = "#BBB";
    	} else {
    		if (o.className == "Scrollbar-Track") o.style.backgroundColor = "#EEE";
    		else o.style.backgroundColor = "#CCC";
    	}
    }
    
    function swapIt(o) {
    	o.blur();
    	if (o.className == "current") return false;
    
    	var list = document.getElementById("Navigation").getElementsByTagName("a");
    	for (var i = 0; i < list.length; i++) {
    		if (list[i].className == "current") {
    			list[i].className = "";
    			document.getElementById(list[i].title).y = -scroller._y;
    		}
    		if (list[i].title == o.title) o.className = "current";
    	}
    
    	list = document.getElementById("Container").childNodes;
    	for (var i = 0; i < list.length; i++) {
    		if (list[i].tagName == "DIV") list[i].style.display = "none";
    	}
    
    	var top = document.getElementById(o.title);
    	top.style.display = "block";
    	scrollbar.swapContent(top);
    	if (top.y) scrollbar.scrollTo(0, top.y);
    
    	return false;
    }
    </script>
    
    <div id="Navigation">
    
      <a href="#" onclick="return swapIt(this)" title="News" class="current">news</a>
      <a href="#" onclick="return swapIt(this)" title="About">about</a>
      <a href="#" onclick="return swapIt(this)" title="Extra">extra</a>
    </div>
    <div id="Container">
      <div id="News">
        <div class="Scroller-Container">
          <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec iaculis, ante et congue feugiat, elit wisi commodo metus, ut commodo ligula enim ac justo. Pellentesque id ligula. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos. Phasellus vitae mi a elit dictum volutpat. Pellentesque nec arcu. Etiam blandit. Phasellus egestas dolor ut lacus. Sed enim justo, sagittis ut, condimentum non, ullamcorper eu, neque. In hac habitasse platea dictumst. Integer ipsum risus, sagittis ac, imperdiet ac, interdum sed, libero. Praesent commodo. Mauris congue, urna eget hendrerit elementum, dolor ligula ultrices neque, in elementum ante erat et elit.</p>
    
          <p>Vivamus vehicula. Integer cursus massa et nisl. Morbi pretium sem eget risus. Vestibulum nec est. Donec feugiat purus et ligula. Quisque semper. Sed eu ante. Curabitur suscipit porttitor libero. Nam eros leo, sollicitudin eget, tincidunt vitae, facilisis a, dui. Proin neque. Aliquam erat volutpat. Pellentesque felis.</p>
          <p>Aliquam consequat. Proin feugiat ultricies dui. Suspendisse mollis dui nec nunc. Nam tristique, ante vitae imperdiet vestibulum, elit nulla rhoncus nisl, vitae tincidunt dolor dui eu mi. In hac habitasse platea dictumst. Nunc blandit dolor vel mauris. Proin wisi. Nam pharetra ultrices tellus. Sed arcu. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nullam ultricies semper wisi. Sed nisl. Donec blandit. Nunc vitae urna sed nisl mattis ornare.</p>
          <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec iaculis, ante et congue feugiat, elit wisi commodo metus, ut commodo ligula enim ac justo. Pellentesque id ligula. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos. Phasellus vitae mi a elit dictum volutpat. Pellentesque nec arcu. Etiam blandit. Phasellus egestas dolor ut lacus. Sed enim justo, sagittis ut, condimentum non, ullamcorper eu, neque. In hac habitasse platea dictumst. Integer ipsum risus, sagittis ac, imperdiet ac, interdum sed, libero. Praesent commodo. Mauris congue, urna eget hendrerit elementum, dolor ligula ultrices neque, in elementum ante erat et elit.</p>
          <p>Vivamus vehicula. Integer cursus massa et nisl. Morbi pretium sem eget risus. Vestibulum nec est. Donec feugiat purus et ligula. Quisque semper. Sed eu ante. Curabitur suscipit porttitor libero. Nam eros leo, sollicitudin eget, tincidunt vitae, facilisis a, dui. Proin neque. Aliquam erat volutpat. Pellentesque felis.</p>
          <p>Aliquam consequat. Proin feugiat ultricies dui. Suspendisse mollis dui nec nunc. Nam tristique, ante vitae imperdiet vestibulum, elit nulla rhoncus nisl, vitae tincidunt dolor dui eu mi. In hac habitasse platea dictumst. Nunc blandit dolor vel mauris. Proin wisi. Nam pharetra ultrices tellus. Sed arcu. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nullam ultricies semper wisi. Sed nisl. Donec blandit. Nunc vitae urna sed nisl mattis ornare.</p>
        </div>
    
      </div>
      <div id="About">
        <div class="Scroller-Container">
          <p>Aliquam consequat. Proin feugiat ultricies dui. Suspendisse mollis dui nec nunc. Nam tristique, ante vitae imperdiet vestibulum, elit nulla rhoncus nisl, vitae tincidunt dolor dui eu mi. In hac habitasse platea dictumst. Nunc blandit dolor vel mauris. Proin wisi. Nam pharetra ultrices tellus. Sed arcu. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nullam ultricies semper wisi. Sed nisl. Donec blandit. Nunc vitae urna sed nisl mattis ornare.</p>
          <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec iaculis, ante et congue feugiat, elit wisi commodo metus, ut commodo ligula enim ac justo. Pellentesque id ligula. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos. Phasellus vitae mi a elit dictum volutpat. Pellentesque nec arcu. Etiam blandit. Phasellus egestas dolor ut lacus. Sed enim justo, sagittis ut, condimentum non, ullamcorper eu, neque. In hac habitasse platea dictumst. Integer ipsum risus, sagittis ac, imperdiet ac, interdum sed, libero. Praesent commodo. Mauris congue, urna eget hendrerit elementum, dolor ligula ultrices neque, in elementum ante erat et elit.</p>
          <p>Vivamus vehicula. Integer cursus massa et nisl. Morbi pretium sem eget risus. Vestibulum nec est. Donec feugiat purus et ligula. Quisque semper. Sed eu ante. Curabitur suscipit porttitor libero. Nam eros leo, sollicitudin eget, tincidunt vitae, facilisis a, dui. Proin neque. Aliquam erat volutpat. Pellentesque felis.</p>
        </div>
    
      </div>
      <div id="Extra">
        <div class="Scroller-Container">
          <p>Vivamus vehicula. Integer cursus massa et nisl. Morbi pretium sem eget risus. Vestibulum nec est. Donec feugiat purus et ligula. Quisque semper. Sed eu ante. Curabitur suscipit porttitor libero. Nam eros leo, sollicitudin eget, tincidunt vitae, facilisis a, dui. Proin neque. Aliquam erat volutpat. Pellentesque felis.</p>
        </div>
      </div>
    </div>
    <div id="Scrollbar-Container">
      <div class="Scrollbar-Up"></div>
    
      <div class="Scrollbar-Down"></div>
      <div class="Scrollbar-Track">
        <div class="Scrollbar-Handle"></div>
      </div>
    </div>
  6. someguy03
    Member
    Posted 3 years ago #

  7. jlevan
    Member
    Posted 3 years ago #

    Where did you upload jsScroller.js and jsScrollbar.js?

    They are not at the location specified in your page. I also tried some more common locations in the theme's directory, but did not see the files.

  8. someguy03
    Member
    Posted 3 years ago #

  9. jlevan
    Member
    Posted 3 years ago #

    http://kylefoleydesign.com/rbfgroup/css/jsScroller.js

    doesn't seem to exist, is that file on the server?

  10. someguy03
    Member
    Posted 3 years ago #

    Woops, the file on the server didn't have a capital S.

    I fixed that, but the javascript still does not work.

    Thanks for helping, hopefully I can get this solved.

  11. jlevan
    Member
    Posted 3 years ago #

    The javascript code should also be pulled out of the page content - insert it directly in the template files. If you look at your generated source, WordPress is scattering <p> tags throughout your script - a small snip:

    <script type="text/javascript">
    var scroller  = null;
    var scrollbar = null;</p>
    <p>window.onload = function () {
      scroller  = new jsScroller(document.getElementById("News"), 400, 180);
  12. someguy03
    Member
    Posted 3 years ago #

    Ah, that worked, thank you! I moved the rest of the javascript into the header. That fixed the javascript but the formatting was still getting messed up by the random line and paragraph breaks all over the HTML as well as you mentioned above.. so I got the Text Control Plugin

    This allowed me to set the post to "no formatting" and removed the code WordPress was inserting.

    Why does WordPress insert hidden HTML even when you are using the HTML tab?

  13. jlevan
    Member
    Posted 3 years ago #

    WordPress modifies the content of a post at several places.

    The tinyMCE editor will add some tags, however, if you flip between the rich editor and the HTML editor, you may notice that the rich editor will display that a block of text is within a <p> tag while at the same time that is not shown in the HTML view - these it appears are just a sort of "this is how it will be displayed after WP formats it" - these tags are not added to the post content at this point.

    You should be able to see this if you save a post and view the post's content in your database (through phpMyAdmin or however you view your database's content) - the post's content will lack any of these automatically inserted <p> tags.

    These tags are added when you call your post content for display using <?php the_content(); ?> - WordPress looks at the content stored in the database and runs several filters over this content.

    More info on this can be found here: http://codex.wordpress.org/How_WordPress_Processes_Post_Content

    As you can freely switch back and forth between the rich text editor and the HTML editor, multiple times while editing a post, as well as the fact that the chosen method is tied to the user, and not the post itself (if you save a post while using the HTML editor, the next post you add/edit will also first display the HTML editor) - WP will not base how it formats a post on which editor you use. The editor choice is considered an author preference, not a format setting.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.