473,548 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

iframe gradual zoom

23 New Member
I would like to gradually resize an iframe in an onmouseover event.
I can easily do it with an image, but when I try to do it with an iframe, it doesn't do anything. So first of all, is it possible to gradually zoom an iframe, and if so, what am I missing?


Here is the script I am trying to manipulate, between the head tags:

Expand|Select|Wrap|Line Numbers
  1. <script language=JavaScript>
  2.  
  3. /**** adjust these two parameters to control how fast or slow
  4. **** the iframes grow/shrink ****/
  5.  
  6. // how many milliseconds we should wait between resizing events
  7.  
  8. var resizeDelay = 10;
  9.  
  10. // how many pixels we should grow or shrink by each time we resize
  11.  
  12. var resizeIncrement = 5;
  13.  
  14. // this will hold information about the iframes we're dealing with
  15.  
  16. var iframeCache = new Object();
  17.  
  18.  
  19. /**
  20. The getCacheTag function just creates a (hopefully) unique identifier for
  21. each <iframe> that we resize.
  22. */
  23.  
  24. function getCacheTag (iframeElement) {
  25. return iframeElement.src + "~" + iframeElement.offsetLeft + "~" + iframeElement.offsetTop;
  26. }
  27.  
  28.  
  29. /**
  30. We're using this as a class to hold information about the <iframe> elements
  31. that we're manipulating.
  32. */
  33.  
  34. function cachediframe (iframeElement, increment) {
  35. this.iframe = iframeElement;
  36. this.cacheTag = getCacheTag(iframeElement);
  37. this.originalSrc = iframeElement.src;
  38.  
  39. var h = iframeElement.height;
  40. var w = iframeElement.width;
  41. this.originalHeight = h;
  42. this.originalWidth = w;
  43.  
  44. increment = (!increment) ? resizeIncrement : increment;
  45. this.heightIncrement = Math.ceil(Math.min(1, (h / w)) * increment);
  46. this.widthIncrement = Math.ceil(Math.min(1, (w / h)) * increment);
  47. }
  48.  
  49.  
  50. /**
  51. This is the function that should be called in the onMouseOver and onMouseOut
  52. events of an <iframe> element. For example:
  53.  
  54. <iframe src='onesmaller.gif' onMouseOver='resizeiframe(this, 150, "onebigger.gif")' onMouseOut='resizeiframe(this)'>
  55.  
  56. The only required parameter is the first one (iframeElement), which is a
  57. reference to the <iframe> element itself. If you're calling from onMousexxx, 
  58. you can just use "this" as the value.
  59.  
  60. The second parameter specifies how much larger or smaller we should resize
  61. the iframe to, as a percentage of the original size. In the example above,
  62. we want to resize it to be 150% larger. If this parameter is omitted, we'll
  63. assume you want to resize the iframe to its original size (100%).
  64.  
  65. The third parameter can specify another iframe that should be used as the
  66. iframe is being resized (it's common for "rollover iframes" to be similar but
  67. slightly different or more colorful than the base iframes). If this parameter
  68. is omitted, we'll just resize the existing iframe.
  69. */
  70.  
  71. function resizeiframe (iframeElement, percentChange, newIframeURL) {
  72. // convert the percentage (like 150) to an percentage value we can use
  73. // for calculations (like 1.5)
  74. var pct = (percentChange) ? percentChange / 100 : 1;
  75.  
  76. // if we've already resized this iframe, it will have a "cacheTag" attribute
  77. // that should uniquely identify it. If the attribute is missing, create a
  78. // cacheTag and add the attribute
  79. var cacheTag = iframeElement.getAttribute("cacheTag");
  80. if (!cacheTag) {
  81. cacheTag = getCacheTag(iframeElement);
  82. iframeElement.setAttribute("cacheTag", cacheTag);
  83. }
  84.  
  85. // look for this iframe in our iframe cache. If it's not there, create it.
  86. // If it is there, update the percentage value.
  87. var cacheVal = iframeCache[cacheTag];
  88. if (!cacheVal) {
  89. iframeCache[cacheTag] = new Array(new cachediframe(iframeElement), pct);
  90. } else {
  91. cacheVal[1] = pct;
  92. }
  93.  
  94. // if we're supposed to be using a rollover iframe, use it
  95. if (newIframeURL)
  96. iframeElement.src = newiframeURL;
  97.  
  98. // start the resizing loop. It will continue to call itself over and over
  99. // until the iframe has been resized to the proper value.
  100. resizeiframeLoop(cacheTag);
  101. return true;
  102. }
  103.  
  104.  
  105. /**
  106. This is the function that actually does all the resizing. It calls itself
  107. repeatedly with setTimeout until the iframe is the right size.
  108. */
  109. function resizeiframeLoop (cacheTag) {
  110. // get information about the iframe element from the iframe cache
  111. var cacheVal = iframeCache[cacheTag];
  112. if (!cacheVal)
  113. return false;
  114.  
  115. var cachediframeObj = cacheVal[0];
  116. var iframeElement = cachediframeObj.iframe;
  117. var pct = cacheVal[1];
  118. var plusMinus = (pct > 1) ? 1 : -1;
  119. var hinc = plusMinus * cachediframeObj.heightIncrement;
  120. var vinc = plusMinus * cachediframeObj.widthIncrement;
  121. var startHeight = cachediframeObj.originalHeight;
  122. var startWidth = cachediframeObj.originalWidth;
  123.  
  124. var currentHeight = iframeElement.height;
  125. var currentWidth = iframeElement.width;
  126. var endHeight = Math.round(startHeight * pct);
  127. var endWidth = Math.round(startWidth * pct);
  128.  
  129. // if the iframe is already the right size, we can exit
  130. if ( (currentHeight == endHeight) || (currentWidth == endWidth) )
  131. return true;
  132.  
  133. // increase or decrease the height and width, making sure we don't get
  134. // larger or smaller than the final size we're supposed to be
  135. var newHeight = currentHeight + hinc;
  136. var newWidth = currentWidth + vinc;
  137. if (pct > 1) {
  138. if ((newHeight >= endHeight) || (newWidth >= endWidth)) {
  139. newHeight = endHeight;
  140. newWidth = endWidth;
  141. }
  142. } else {
  143. if ((newHeight <= endHeight) || (newWidth <= endWidth)) {
  144. newHeight = endHeight;
  145. newWidth = endWidth;
  146. }
  147. }
  148.  
  149. // set the iframe element to the new height and width
  150. iframeElement.height = newHeight;
  151. iframeElement.width = newWidth;
  152.  
  153. // if we've returned to the original iframe size, we can restore the
  154. // original iframe as well (because we may have been using a rollover
  155. // iframe in the original call to resizeiframe)
  156. if ((newHeight == cachediframeObj.originalHeight) || (newWidth == cachediframeObj.originalwidth)) {
  157. iframeElement.src = cachediframeObj.originalSrc;
  158. }
  159.  
  160. // shrink or grow again in a few milliseconds
  161. setTimeout("resizeiframeLoop('" + cacheTag + "')", resizeDelay);
  162. }
  163.  
  164. </script>
  165.  


and in the iframe tag:

Expand|Select|Wrap|Line Numbers
  1.  onmouseover="resizeIframe(this, 350)" onmouseout="resizeIframe(this)"
I've also tried:

Expand|Select|Wrap|Line Numbers
  1.  onmouseover='resizeIframe(this, 350, "player.htm")' onmouseout='resizeIframe(this)'
and neither works.
Oct 9 '07 #1
1 8118
acoder
16,027 Recognized Expert Moderator MVP
resizeIframe should be "resizeifra me" (lower-case i).
Nov 6 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2562
by: apk | last post by:
Hi All, I am currently working on a project that displays preview of a jpeg in an iframe. we can edit this preview - like increasing its zoom level and changing pages , images etc. This works fine with IE on windows but when it comes to Safari on Mac , the preview is lost on refreshing the browser.
0
1489
by: davide rocchelli | last post by:
I have found a probable bug when you draw with GDI. Look this simple code Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint Const Zoom As Single = 0.001 Dim p As Pen
2
12668
by: Mo Ade via .NET 247 | last post by:
How do I write code to include a zoom feature in my project so that when my Vb Form loads an image I can click in my main menu zoom in or zoom out? -------------------------------- From: Mo Ade ----------------------- Posted by a user from .NET 247 (http://www.dotnet247.com/) <Id>6aW7IUJA+0CCEGJ4S8DRuA==</Id>
1
2287
by: adobefriedman | last post by:
I have an interactive flash map application that use javascript Flash gateway and asp to identify sales reps worldwide. Upon zooming into a particular country, an iframe panel slides out and displays the associated rep information. The client would like to include a link on the iframe that returns the user to the worldwide map and basically...
3
15585
by: jnag | last post by:
I am trying to implement font changer, where I have links on the banner of the site and when the user clicks on the links, the font size of the page has to change. I tried document.body.style.fontSize='50%' for example, on an onclick() event, but it did not work. I tried zooming with the following code, and it works: <td...
3
5373
polymorphic
by: polymorphic | last post by:
I have succeeded in embedding PDF files in a dynamic iframe. The problem is that I need the PDF to cache. If the PDF remains the same from page load to page load then the pdf is somehow cached with the html page. But if I try to navigate to another pdf in the IFRAME then no caching occurs. Is the problem in the IFRAME reloading instead of just...
0
8294
by: murry19830507 | last post by:
i want creat an web application(c#.net),which contains an image and one radiobutton list with 3 radiobuttons(zoom in ,zoom out ,zoom window) when user checked on zoom in imge has to be zoom inthe similar manner when zoom window is checked,it allow to create a rectangle window by using mouse pressed and released.and particular area of the...
0
7438
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7951
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7466
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7803
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6036
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5082
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3495
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1926
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
751
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.