Results 1 to 3 of 3

Thread: [RESOLVED] Setting css in javascript

  1. #1

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Resolved [RESOLVED] Setting css in javascript

    I'm trying to make my webpage dynamically resizable. What's wrong with my code?

    Code:
    window.onresize = function(e) { 
      var percentage = (100 / 1920) * window.width;
      var offset = 30 + (30 - ((percentage / 100) * 30));
      $(".mySlides img, .mySlides iframe").style.width = (percentage)%;
      $(".mySlides img, .mySlides iframe").style.height = (percentage)%;
      $(".slideshow-container").style.margin-left = (offset)%;    
    }

  2. #2
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,660

    Re: Setting css in javascript

    Well its difficult to tell just from what you have posted as without seeing the web page itself we cant tell what its acting on. can you post any of your webpage? and the stylesheet?

    You function looks to basically look like it should work but .... could you tell us what is actually happening?

    If its just not working at all and i had to guess then styles you have elsewhere could potentially be blocking the resize from working correctly.

    Have you debugged using Firebug in Firefox? does your JavaScript have any errors?

    My only other comment is why would you do it this way through JavaScript rather than directly through styles?

    why not just make all your sizing relative?
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  3. #3
    Hyperactive Member coothead's Avatar
    Join Date
    Oct 2007
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    284

    Re: Setting css in javascript

    Hi there .paul.

    "What's wrong with my code?"
    Well, for starters, here are a just a few of the errors...
    Code:
    
    (percentage)%;
    
    and 
    
    (offset)%;
    ...should be...

    Code:
    
    percentage+'%';
    
    and 
    
    offset+'%'
    ...and this...
    Code:
    
    margin-left
    ...should be...
    Code:
    
    marginLeft
    Having said that, you really do not need "JavaScript" to do this task.

    Vanilla CSS is more than capable of doing the leverage.

    coothead


    ~ the original bald headed old fart ~

Posting Permissions

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



Click Here to Expand Forum to Full Width