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 7 of 7
  1. #1
    Regular Coder
    Join Date
    Nov 2010
    Posts
    432
    Thanks
    56
    Thanked 1 Time in 1 Post

    Trouble Passing Variable

    Hiya

    The Variable:
    Code:
    BottomNavfontRadius = (BottomNavWidth / 2.5).toFixed();
    Where it needs to go:
    Code:
                    $example2.show().arctext({
                        radius: 200,
                        dir: -1
                    });
    The variable is to replace the 'radius: 250,' as this is only correct for my current resolution. I need the variable to be set there, however my tries have failed so far.

    Live Demo: Untitled Document

    I'm sure there is a simple solution I'm overlooking?

    Thank you for any help in advanced,
    Best Regards,
    Tim
    Last edited by MrTIMarshall; 04-16-2014 at 07:01 PM.

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    You should declare that variable. Not declaring will make it an implicit global variable which is not good.
    Code:
    var WindowWidth,
         WindowHeight,
         BottomNavfontRadius,
         ...
    Then put that variable directly to the radius option as it looks like the variable is already set at that point.

    Code:
    radius: BottomNavfontRadius,
    You can always debug and put a break point to check if that variable is set by the time you call the arctext() plugin method.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    Regular Coder
    Join Date
    Nov 2010
    Posts
    432
    Thanks
    56
    Thanked 1 Time in 1 Post
    Quote Originally Posted by glenngv View Post
    You should declare that variable. Not declaring will make it an implicit global variable which is not good.
    Code:
    var WindowWidth,
         WindowHeight,
         BottomNavfontRadius,
         ...
    Then put that variable directly to the radius option as it looks like the variable is already set at that point.

    Code:
    radius: BottomNavfontRadius,
    This was the first thing I tried, I never uploaded like this to show what it should look like, however the live version has now been updated to show you the result.

    Quote Originally Posted by glenngv View Post
    You can always debug and put a break point to check if that variable is set by the time you call the arctext() plugin method.
    How do I do this as it is obviously not setting before the arch is applied?

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    The BottomNavfontRadius variable is not set before the arch is applied because the resizeHandler function which is were you set the variable is debounced to 250 ms which means the function will only be called after 250 ms.

    Fix it by changing this:

    Code:
    $(document).ready(function () {
        $(window)
            .on('resize', debounce(resizeHandler, 250)) //test different rates and adjust accordingly
            .trigger('resize'); //execute on page load
    });
    to:
    Code:
    $(document).ready(function () {
        $(window).on('resize', debounce(resizeHandler, 250)) //test different rates and adjust accordingly
        resizeHandler(); //execute on page load immediately
    });
    To debug in Chrome, press F12 or right-click anywhere on the page and choose Inspect Element. Then go to Sources tab and then open the file that you want to debug, in your case, it's example.html which is where your script is. Then put breakpoints (click the left column with the line numbers) at different lines in your code which you want to keep track on. Then reload the page. The script should stop in your breakpoints and you can press F10 to execute the script line by line. You can watch the variables as you go step by step by adding it in the Watch Expressions section or in the Console or by hovering over the variable.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #5
    Regular Coder
    Join Date
    Nov 2010
    Posts
    432
    Thanks
    56
    Thanked 1 Time in 1 Post
    Thank you for your reply glenngv,

    I'm a little bit more confused now. Manually setting the variable it needs to be approx 250 for my screen and the calculation variable you helped with equals 253, however please see the updated view for the result.

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Then your calculations are off.

    BottomNavWidth = (WindowWidth / 2.632).toFixed();
    ...
    BottomNavfontRadius = (BottomNavWidth / 0.8).toFixed();

    I don't know how you came up with those divisors.

    Btw, don't use toFixed() to round off numbers, use Math.round() instead. toFixed() (although it rounds off the number) returns a string not number.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #7
    Regular Coder
    Join Date
    Nov 2010
    Posts
    432
    Thanks
    56
    Thanked 1 Time in 1 Post
    Code:
    BottomNavWidth = (WindowWidth / 2.632).toFixed();
    The above calculates the width surrounding the bottom scroll image area, where you should see, or partially see the links. It has been tested on multiple devices and scales accordingly.

    Code:
    BottomNavfontRadius = (BottomNavWidth / 0.8).toFixed();
    The above is a little guess work at this moment of time. The links radius for my resolution look good at a 250 radius and this calculation brings up 253, only fractions of. I cannot say this works for all devices as of yet, I got stopped in my tracks trying to pass the variable over.


  •  

    Posting Permissions

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