dcsimg
www.webdeveloper.com
Results 1 to 5 of 5

Thread: function(help)...

  1. #1
    Join Date
    Dec 2010
    Posts
    6

    function(help)...

    I am working on image gallery and so far I have found several that come close to doing what I want but none that simply do it right... so the obviously solution is to write my own gallery script... Or so thats what I thought days ago when I started this project.

    After stumbling around, I have finally figured out what I need to make use of .innerHTML replacements

    I want to show a list of thumbnail images, next to the main content container. When mousing over the thumbnail the content of the main content container would be replaced. <a onMouseOver='swap(content)'>

    I know it needs to be done through an .innerHTML= replacement because I intend on filling the main content container with images <img>, flash video <object .flv>, and embed quicktime plugins <embed .mov>. I have successfully tested these replacements with very simple scripts like:

    function MainContentSwap(){
    document.getElementById('MainContentContainer').innerHTML = '<img src="..replacementImage" ></img>'; }

    function MainContentReturn(){
    document.getElementById('MainContentContainer').innerHTML = '<img src="orginalImage" ></img>';}


    But I would need a function for every thumbnail, which would be ridiculous.
    So I need an array of thumbnails and of replacement divs, I think..?

    <a id=thumbnail, #" onMouseOver='MainContentSwap'><img src="..." /></a>
    <div id="MainContent, #" class="hidden"><"img or .flv or .mov"> </div>

    I would appreciate and advice or links to useful How Tos...

  2. #2
    Join Date
    Dec 2010
    Posts
    6

    function (help)... V2

    After nearly 50 people have looked at my previous post without reply I figured my question was not clear, so maybe this will make more sense.

    In the head...

    <script type="text/javascript" >
    function MainContentSwap(idNumber){
    document.getElementById('MainContentContainer').innerHTML = [idNumber];
    }
    </script>


    Later in the body...

    <a id="thumbnail" onMouseOver="MainContentSwap(1)"><img src="images/image1.jpg"></a>
    <div id="1" class="hidden"><img src="/V2/image-slideshow-vertical/images/image1_big.jpg"/> </div>

    <a id="thumbnail" onMouseOver="MainContentSwap(2)"><img src="images/image2.jpg"></a>
    <div id="2" class="hidden"><img src="/V2/image-slideshow-vertical/images/image2_big.jpg"/> </div>

    <a id="thumbnail" onMouseOver="MainContentSwap(3)"><img src="images/image3.jpg"></a>
    <div id="3" class="hidden"><img src="/V2/image-slideshow-vertical/images/image2_big.jpg"/> </div>

    <a id="thumbnail" onMouseOver="MainContentSwap(4)"><img src="images/image4.jpg"></a>
    <div id="4" class="hidden"><img src="/V2/image-slideshow-vertical/images/image4_big.jpg"/> </div>

    There are more but the format does not change.
    Currently if I mouse over any of the thumbnails, the # from MainContentSwap(#) is input into the function and output into theMainContentContainer as only the #. Literally a number (1,2,3,etc) floating in the middle of the div 'MianContentContainer' all by itself.

    I need it to output the entire div that has that id="#".

    I have tried div[idNumber], with no luck.

    Any ideas..?

  3. #3
    Join Date
    Aug 2009
    Posts
    593
    Hopefully what you are looking for...

    HTML Code:
    <!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" xml:lang="en" lang="en">
    	<head>
    		<title>Image Gallery</title>
    		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    		<style type="text/css">
    
    			.thumbnail IMG {
    				border: solid 1px black;
    				width: 50px;
    				height: 50px;
    			}
    			.hidden {
    				display: none;
    			}
    			#MainContentContainer {
    				border: solid 1px black;
    				width: 200px;
    				height: 200px;
    			}
    
    		</style>
    
    		<script type="text/javascript">
    
    			function MainContentSwap(idNumber){
    				document.getElementById('MainContentContainer').innerHTML = document.getElementById('E' + idNumber).innerHTML;
    			}
    
    		</script>
    
    	</head>
    	<body>
    
    		<div id="MainContentContainer"></div>
    
    		<a class="thumbnail" onmouseover="MainContentSwap(1);"><img src="images/image1.jpg" alt="" /></a> 
    		<div id="E1" class="hidden"><img src="/V2/image-slideshow-vertical/images/image1_big.jpg" alt="" /></div>
    
    		<a class="thumbnail" onmouseover="MainContentSwap(2);"><img src="images/image2.jpg" alt="" /></a> 
    		<div id="E2" class="hidden"><img src="/V2/image-slideshow-vertical/images/image2_big.jpg" alt="" /></div>
    
    		<a class="thumbnail" onmouseover="MainContentSwap(3);"><img src="images/image3.jpg" alt="" /></a>
    		<div id="E3" class="hidden"><img src="/V2/image-slideshow-vertical/images/image2_big.jpg" alt="" /></div>
    
    		<a class="thumbnail" onmouseover="MainContentSwap(4);"><img src="images/image4.jpg" alt="" /></a> 
    		<div id="E4" class="hidden"><img src="/V2/image-slideshow-vertical/images/image4_big.jpg" alt="" /></div>
    
    	</body>
    </html>
    I added some extra styles you may not need, just so I could see where the images were.
    Ids should not start with a number, and should also be unique (thumbnail).

  4. #4
    Join Date
    Dec 2010
    Posts
    6
    Thanks for the update, that really helps.

    Now I can move on to step number 2, fading between one image and the next.

    : )

  5. #5
    Join Date
    Dec 2010
    Posts
    6
    Quote Originally Posted by thraddash View Post
    Hopefully what you are looking for...

    Thanks again for getting me on the right path. : )
    Feel free to check out the finished product: http://mgarito.com/V2/Pages/firefly.php


    Note this is the only page that has been rebuilt, so bulk of the menu links will not work.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles