Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

JQuery CSS script

Posted on 2013-06-03
3
371 Views
Last Modified: 2013-06-03
HI

I am trying to set some CSS values om an iframe.
However it seems that my JQuery script does not execute.

Can anyone point me in the right direction. Please bare in mind that i am very new to JQuery/Javascript.

 
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
function autoResize(myframe) {
    
	$ww = $(window).width();
	
	
	if(ww < '1000') {
	  wm = (ww + 1000) / 1000;
	  $('#myframe').css({
      'width': '1000px',
	  'height': '200px',
	  'position': 'relative',
	  'top': '0px',
	  '-ms-zoom': wm,
	  '-moz-transform': 'scale('+ wm + ')',
	  '-moz-transform-origin': '0px 0',
	  '-o-transform': 'scale('+ wm + ')',
	  '-o-transform-origin': '0 0',
	  '-webkit-transform': 'scale('+ wm + ')',
	  '-webkit-transform-origin': '0 0'
	  
      });
	  
    } 
    else {
	 $('#myframe').css({
      'width': '1000px',
	  'height': '200px',
	  'position': 'relative',
	  'top': '0px',
	  '-ms-zoom': '1.0',
	  '-moz-transform': 'scale(1.0)',
	  '-moz-transform-origin': '0px 0',
	  '-o-transform': 'scale(1.0)',
	  '-o-transform-origin': '0 0',
	  '-webkit-transform': 'scale(1.0)',
	  '-webkit-transform-origin': '0 0'
	  });
    }
	

}
</script>
<style>
    body{
		margin:0px;
		padding:0px;
	}
	
	#wrap { width: 1000px; height: 200px; padding: 0; position:relative; top:0px; overflow: hidden; background:#666666; }
</style>
</head>

<body>

<div id="wrap">
    <iframe id="myframe"  src="/_adv/edgetest/Untitled-1.html" frameborder="0" onload="autoResize(this);"></iframe>
</div>

</body>
</html>

Open in new window

0
Comment
Question by:kbnewgear
3 Comments
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 39216768
It would be easier to diagnose if you post a link to the page.  As a guess it looks like you are executing the scripting before the page is loaded.  You probably need a $(document).ready()

Cd&
0
 
LVL 18

Expert Comment

by:Rajar Ahmed
ID: 39216821
Try this  changes,
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script>
<script type="text/javascript">
    function autoResize(myframe) {
        $ww = $(window).width();
        
        if ($ww < '1000') {
            wm = ($ww + 1000) / 1000;
            $('#myframe').css({
                'width': '1000px',
                'height': '500px',
                'position': 'relative',
                'top': '0px',
                '-ms-zoom': wm,
                '-moz-transform': 'scale(' + wm + ')',
                '-moz-transform-origin': '0px 0',
                '-o-transform': 'scale(' + wm + ')',
                '-o-transform-origin': '0 0',
                '-webkit-transform': 'scale(' + wm + ')',
                '-webkit-transform-origin': '0 0'
            });
        }
        else {
            $('#myframe').css({
                'width': '1000px',
                'height': '500px',
                'position': 'relative',
                'top': '0px',
                '-ms-zoom': '1.0',
                '-moz-transform': 'scale(1.0)',
                '-moz-transform-origin': '0px 0',
                '-o-transform': 'scale(1.0)',
                '-o-transform-origin': '0 0',
                '-webkit-transform': 'scale(1.0)',
                '-webkit-transform-origin': '0 0'
            });
        }
    }
</script>

Open in new window

0
 
LVL 55

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 39216838
&cd - he is not invoking the auto-resize event until the iframe loads - so document.ready not required.

Why don't you use dynamic stylesheets to style for different media widths

http://www.w3.org/TR/css3-mediaqueries/
http://css-tricks.com/resolution-specific-stylesheets/

Rather than using JQuery.

Other than that you have an error in your script

$ww = $(window).width()

should be
var ww = $(window).width()
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question