Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Mar 2005
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    clearTimeout() function won't work

    hi, it's me again!

    i have a set of images next to each other on a div in an iframe. if i klick a link i'd like the layer to scroll one image and not more. unfortunately my clearTimeout() function won't work – it scrolls through all images when i click only once, despite my stopfunction... can you see what's wrong?

    after the i = 0 i call stopscroll() –*but it won't stop scrolling

    thx!

    Code:
    function moveleft() {
    
    			if (window.rightvar) {
    				stopscroll()
    			}
    			
    			if(parseInt(scrollframename.document.getElementById('scroll').style.left) == 0
    		|| parseInt(scrollframename.document.getElementById('scroll').style.left) == -649
    		|| parseInt(scrollframename.document.getElementById('scroll').style.left) == -1298 
    		|| parseInt(scrollframename.document.getElementById('scroll').style.left) == -1947 
    		|| parseInt(scrollframename.document.getElementById('scroll').style.left) == -2596 
    		|| parseInt(scrollframename.document.getElementById('scroll').style.left) == -3245) 
    			{	i=0 
    				stopscroll()				
    			}
    		
    			i++
    			
    			z = 2.135*i*Math.pow(e,-1/8*i)
    			scrollframename.document.getElementById('scroll').style.left = parseInt(scrollframename.document.getElementById('scroll').style.left)-speed*z+"px"
    			leftvar = setTimeout("moveleft()",update)	
    		}
    stopscroll()
    Code:
    function stopscroll() {		
    			if (window.leftvar) 
    				clearTimeout(leftvar)
    			if (window.rightvar) 
    				clearTimeout(rightvar)
    		}

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Posts
    626
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Are your variables rightvar and leftvar defined within the function moveleft()? If they are then your stopscroll() function does not have access to them as they are local to the script they are defined in. You need to make them global variables by defining them outside of a specific function.

  • #3
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Please, give us a link to an example of this script in action.

    Some tips, though:
    - The function setInterval is smoother than setTimeout, because the timing doesn't get affected by the execution time.
    - Store away the scrollframename.document.getElementById('scroll') reference in a variable (e.g. oElm) instead of looking it up time after time.
    - Also, store away the parseInt(oElm.style.left) part in another variable (e.g. iPos).
    - Instead of comparing to 0, -649, -1298 etc, do iPos%649==0.
    - Use -0.125 instead of -1/8.
    - You can use a single scroller function instead of one right and one left scroller if you pass a simple argument (e.g. iDir) that is either -1 for left or 1 for right, and replace the -speed part with +speed*iDir.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #4
    New Coder
    Join Date
    Mar 2005
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks for the hints, it has been a while since i learned to programm


    here's a link to the script in action:

    http://www.redundanz.ch/private/gleitenderlayer.html

    i defined the leftvar and rightvar so it's global, but it still scrolls through all of the images rather then through just one

    can you figure out why?

  • #5
    New Coder
    Join Date
    Mar 2005
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i always get en error when doing this:

    var oElm = scrollframename.document.getElementById('scroll')
    var iPos = parseInt(oElm.style.left)

    it says: scrollframename not defined

    but when i'm addressing it directly, it's no problem...

    edit: when i'm doing it like this:

    var iElm = document.getElementById('scrollframename')

    i get an iElm.hastnoProperties error...
    Last edited by drdre; 03-07-2005 at 07:32 PM.

  • #6
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Oh, I forgot that. Iframes are a little peculiar.
    Code:
    var
        oIframe=document.getElementById('scrollframeid'),
        oIframeDoc=oIframe.contentDocument||oIframe.document;
    Here you must note that neither of these work in the Safari browser.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #7
    New Coder
    Join Date
    Mar 2005
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts
    oh damn, i'm using safari... is there no other way to do this?

    did you see what was my error with scrolling?

  • #8
    New Coder
    Join Date
    Mar 2005
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i'm starting to hate javascript

    when i scroll to the left with z = 2.135*i*Math.pow(e,-1/8*i)

    and then back to the right with the very same forumla, well, guess what, it doesn't scroll the same distance!

    i'm really confused now.

  • #9
    New Coder
    Join Date
    Mar 2005
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok, i did it!

    but it only scrolls to the left side because javascripts didn't manage to get my additions right (don't know why..) and i was too stupid to figure something better out

    style.left = parseInt(style.left) - speed * function scrolls to the left, whereas style.left = parseInt(style.left) + speed * function scrolls to the right, but with a very strange distance.

    although it should be the same distance, it scrolls much more, maybe it has something to do with how addition of float units (function is an infinite number) works.

    anyway, i found a page, where this problem has been solved (but i don't know how). you may want to look into it, it's really nice (though 4 years old i think).

    the page is: http://www.kandahar-vintage.ch/history.htm

    maybe some of you figure out how they did it and post a free dhtml script

    thnx anyways, good forum here.


  •  

    Posting Permissions

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