Results 1 to 3 of 3

Thread: Need help with image hover js effect

  1. #1
    Join Date
    Jan 2011
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Talking Need help with image hover js effect

    Script Title: DOM image rollover

    Script URL (on DD): http://www.dynamicdrive.com/dynamicindex15/domroll.htm



    This img hover effect works - but for a short period of time!
    When I update it at my blog (http://districtofbrokendreams.blogspot.com/), it works for 2 or 3 hours, then it stops working even if I don't touch any code of my page. Why? How? How can I make it work?
    I use blogger, so, instead of uploading the javascript file to any server, I used the one the was already on DD (http://www.dynamicdrive.com/dynamici...hrisdomroll.js).
    Can you help me?

    Also, it used to work normally, but I don't remember what I did before. I erased it all once and had to start again.

    Thaaanks!
    Last edited by Riku; 01-10-2011 at 06:57 PM.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    You cannot link directly to the script on Dynamic Drive. Its servers prevent 'hotlinking'. It will appear to work perhaps for as long as you have the script in your browser's cache. But once that expires, the hotlink will no longer work.

    This also means that for others, it generally will never work.

    If you need a remote host for your script, find another and upload it there. Or you could just put the script directly on the page. That is if your blog host allows that.

    replace:

    Code:
    <script src='http://www.dynamicdrive.com/dynamicindex15/chrisdomroll.js' type='text/javascript'/>
    </script>
    with:

    Code:
    <script type="text/javascript">
    //=====================================================================
    //  DOM Image Rollover v3 (hover)
    //
    //  Demo: http://chrispoole.com/scripts/dom_image_rollover_hover
    //  Script featured on: Dynamic Drive (http://www.dynamicdrive.com)
    //=====================================================================
    //  copyright Chris Poole
    //  http://chrispoole.com
    //  This software is licensed under the MIT License 
    //  <http://opensource.org/licenses/mit-license.php>
    //=====================================================================
    
    function domRollover() {
    	if (navigator.userAgent.match(/Opera (\S+)/)) {
    		var operaVersion = parseInt(navigator.userAgent.match(/Opera (\S+)/)[1]);
    	}
    	if (!document.getElementById||operaVersion <7) return;
    	var imgarr=document.getElementsByTagName('img');
    	var imgPreload=new Array();
    	var imgSrc=new Array();
    	var imgClass=new Array();
    	for (i=0;i<imgarr.length;i++){
    		if (imgarr[i].className.indexOf('domroll')!=-1){
    			imgSrc[i]=imgarr[i].getAttribute('src');
    			imgClass[i]=imgarr[i].className;
    			imgPreload[i]=new Image();
    			if (imgClass[i].match(/domroll (\S+)/)) {
    				imgPreload[i].src = imgClass[i].match(/domroll (\S+)/)[1]
    			}
    			imgarr[i].setAttribute('xsrc', imgSrc[i]);
    			imgarr[i].onmouseover=function(){
    				this.setAttribute('src',this.className.match(/domroll (\S+)/)[1])
    			}
    			imgarr[i].onmouseout=function(){
    				this.setAttribute('src',this.getAttribute('xsrc'))
    			}
    		}
    	}
    }
    domRollover();
    </script>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    Riku (01-10-2011)

  4. #3
    Join Date
    Jan 2011
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thank you so much! I think it worked.

    What I didn't understand was the thing about working for some time and then not working anymore. That was totally nonsense to me untill you explained it.

    Now it works! And I think it'll last.


Bookmarks

Posting Permissions

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