Solved

JQuery CSS script

Posted on 2013-06-03
3
364 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
Comment Utility
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
Comment Utility
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 51

Accepted Solution

by:
Julian Hansen earned 500 total points
Comment Utility
&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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now