SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2008
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    variable declarations in an array

    hello,

    just wondering if this could be changed from the following:

    T1 = new Array("graphics/cursor/valentine1.gif",80,31,"graphics/cursor/valentine1.gif",80,31,
    "graphics/cursor/valentine1.gif",80,31,"graphics/cursor/valentine1.gif",80,31,
    "graphics/cursor/valentine1.gif",80,31,"graphics/cursor/valentine1.gif",80,31)

    to a variable declaration: replace the "graphics/cursor/valentine1.gif", with a variable name: T1 = new Array("' + cursor-name + '",80,31).

    to where instead of the cursor being "harded coded" it is a variable.

    thanks,
    john....

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    foo = 'cursor5'
    T1 = new Array("graphics/" + foo + "/valentine1.gif",80,31,

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2008
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by crmalibu View Post
    Code:
    foo = 'cursor5'
    T1 = new Array("graphics/" + foo + "/valentine1.gif",80,31,
    so with the above statement, it would also work like this:

    foo = 'valentine1'
    T1 = new Array("graphics/cursor/" + foo + ".gif", 80 ,31)

  4. #4
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    BTW, There is no need to use "new Array" - It's better to use var array = [];

    ::

    You can also mix and match as much as you like in arrays:

    Code JavaScript:
    var name = 'Mickey Mouse';
    var foo = 'hello' + ' ' + name;
    var array = [
    	foo,
    	1+2,
    	1000,
    	'a string',
    	{
    		prop1: 'value 1',
    		prop2: 'value 2'
    	},
    	['a','b','c','d','e']
    ];
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)

  5. #5
    SitePoint Enthusiast
    Join Date
    Jul 2008
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hello all,

    i have another queston, look at the CSS code below:

    <style type="text/css"> body { cursor: url('graphics/cursor/romantic_1.cur'); } a {cursor: url('graphics/cursor/bible_1.cur');}</style>

    the question is, is it possible to have variables in the above statement? like this:

    <style type="text/css"> body { cursor: url(cursor1); } a {cursor: url(cursor2);}</style>

    where the hard coded URL 'graphics/cursor/romantic_1.cur' is replaced with the variable name cursor1?

    or is variables not allowed in CSS...

    thanks,
    john....

  6. #6
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You cannot place JavaScript vairables in CSS - but you can apply inline styles to an element using JavaScript:

    Code JavaScript:
    element.style.cursor = 'url(' + cursor1 + ')';
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)

  7. #7
    SitePoint Enthusiast
    Join Date
    Jul 2008
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by JimmyP View Post
    You cannot place JavaScript vairables in CSS - but you can apply inline styles to an element using JavaScript:

    Code JavaScript:
    element.style.cursor = 'url(' + cursor1 + ')';
    i have tried to implement the above and cant get it to work.... how do you implement te above so it will change the cursor. do you place it inside the <script></script> or is it called someother way....

    thanks
    john....

  8. #8
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that is javascript.

    element would be a DOM element.


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
  •