Example code

Linux howto's, compile information, information on whatever we learned on working with linux, MACOs and - of course - Products of the big evil....
Post Reply
User avatar
^rooker
Site Admin
Posts: 1483
Joined: Fri Aug 29, 2003 8:39 pm

Example code

Post by ^rooker »

Here's my code for synchronizing horizontal scrolling of multiple graphs within iframes:
(It's a mix between PHP and javascript)

Code: Select all

<html>
    <head>
        <script type="text/javascript">
            var frame_count = <?=count($_graphs)?>;
            var master_graph = "graph_0";

            function init_scroll()
            {
                var frame = document.getElementById(master_graph).contentWindow;
                frame.onscroll = function ()
                {
                    scroll_sync();
                }
            }

            function scroll_sync()
            {
                var frame = document.getElementById(master_graph);
                var x = frame.contentWindow.pageXOffset;

                for (i=1; i<frame_count; i++)
                {
                    document.getElementById("graph_" + i).contentWindow.scrollTo(x, 0);
                }
            }
        </script>
    </head>

    <body OnLoad="init_scroll();">
    <?php foreach ($_graphs as $index=>$graph): ?>
        <iframe name="graph_<?=$index ?>" id="graph_<?=$index ?>"
                src="<?=$graph ?>" frameborder="0"
                scrolling="auto" width="100%" height="320"></iframe>
    <?php endforeach; ?>
    </body>
</html>
Jumping out of an airplane is not a basic instinct. Neither is breathing underwater. But put the two together and you're traveling through space!
Post Reply