example12.php HOME Examples overview Download Ask a question
example14.php

AJAX-ZOOM - load zoom & 360 degree viewer in an (responsive) iframe

There are several reasons why you would want to embed AJAX-ZOOM into an iframe. In fact this is the easiest way to embed AJAX-ZOOM as you do not need the jQuery core in the parent page and you do not need any other scripts too. One of the immanent reasons is that because of simple API usage and programming you can not have more than one instances of AJAX-ZOOM showing simultaneously at a time within one page. You can however switch between several instances like in example29.php.

If your iframe is responsive and AJAX-ZOOM is triggered fullscreen inside this iframe, then it will adjust instantly when iframe is resized. Additionally you can place more than one player into a page. Mouse wheel zoom on player is disabled in this examples when the player is not in fullscreen view but it can be enabled if needed. Please note that "cross-domain" usage is not supported by the regular license.

New: if you include "/axZm/axZm.iframe.js" into parent page (e.g. like this page with iframes) and pass iframe ID to the player over query string, then fullscreen will also work for mobile devices.

360° spin Local

Not triggered with browser API fullscreen and does work on mobile devices including IOS without opening new window or something like that.


<!--
* Copy only axZm.iframe.js once into head or body, 
* No other files from AJAX-ZOOM are needed on the page / server which includes iframe 
* jQuery is not needed
* PHP is not needed -> this page could be HTML

* axZm.iframe.js is only needed if you want AJAX-ZOOM player 
* to be able to open at fullscreen on mobile devices from within iframe 
* or full browser window on any device when AJAX-ZOOM option "fullScreenApi" is disabled
* allowfullscreen is not needed then
-->
<script type="text/javascript" src="../axZm/axZm.iframe.js"></script>

<!--
* The iframe element can be responsive
* It should have an (unique) ID!
* The value of its ID should be passed as "iframeID" parameter to AJAX-ZOOM

* example33_vario.php is just an example which is prepared to respond to several parameters
* You can create your own file or change the parameters, 
* retrieve data from DB within this file or whatever...

* PARAMETERS of example33_vario.php TO DEFINE WHICH DATA TO LOAD
* @ 3dDir - path to folder with 360 degree images, or
* @ zoomData - multiple 2D image paths devided by vertical dash |, or
* @ zoomDir - path to folder with several images for gallery

* SOME OPTIONAL PARAMETERS, AJAX-ZOOM HAS HUNDREDS OTHER
* @ spinReverse - reverse spin direction
* @ spinReverseZ - reverse spin direction for 3D on vertical axis
* @ spinBounce - should be enabled when it is e.g. about 180 degree spin and not full 360 rotation
* @ mouseScrollEnable - disable mouse wheel zoom for desktop devices when not in fullscreen
* @ spinNoInit - do not start spinning on load
* @ fullScreenApi - if 0 or false is passed, the player will not use fullscreen desktop browser API
* @ stepZoom - disable zoom transition when zooming with mouse wheel

* @ example - value of configuration - set defined in /axZm/zoomConfigCustom.inc.php
			  default "example" value in example33_vario.php is "spinIpad"
			  in /axZm/zoomConfigCustom.inc.php you can create your own sets
-->
<iframe 
	class="ajaxzoom_iframe" 
	width="100%" 
	frameborder="0" 
	id="ajaxzoom_frame_1" 
	src="example33_vario.php?3dDir=/pic/zoom3d/Uvex_Occhiali&fullScreenApi=0&spinReverse=0&mouseScrollEnable=1&spinNoInit=1&iframeID=ajaxzoom_frame_1" 
	scrolling="no" 
	allowfullscreen>
</iframe>

Replace some image (or any other html element) on click with AJAX-ZOOM 360 product spin, AJAX-ZOOM gallery or whatever else

Here we have a DIV element which contains an image as placeholder. The DIV has a class "ajaxzoom_image" which can be changed if you wish. It only sets the desired proportion which can be achieved with various CSS methods or JS. The "data-src" attribute contains the link to a file including parameters and sets the desired content you want to load into AJAX-ZOOM player. This can be a 360/3D, plain image or gallery...


				
<div class="ajaxzoom_image" 
	data-src="https://www.ajax-zoom.com/examples/example33_vario.php?3dDir=/pic/zoom3d/Canon_1100D&mouseScrollEnable=1&fullScreenApi=0">
	<img src="../axZm/icons/media-360-1200.png">
</div>
							

Now we only need some JavaScript to replace this image with the iframe when the user clicks on that DIV. It creates an iframe element with jQuery and sets "src" attribute taken from "data-src" of the div. The id of the element is instantly passed over query string as additional parameter. Since "ajaxzoom_image" is a CSS class selector, the below code can be applied to more than one DIV and you only need to insert this JavaScript once.


				
<script type="text/javascript" src="../axZm/axZm.iframe.js"></script>
<script type="text/javascript">
jQuery("body").on("click", ".ajaxzoom_image", function() {
	if ($(this).attr("data-isrc")) {
		// generate a unique ID if not present
		// other than class the ID of an element should be unique anyway
		if (!$(this).attr("id")) {
			var min = 11111111111;
			var max = 99999999999;
			$(this).attr("id", "ajaxzoom_" + new Date().getTime() + Math.floor(Math.random() * (max - min + 1)) + min)
		}
		// create iframe and put as src the data-src of the div
		var iframe = $("<iframe />");
		iframe.attr({
			width: "100%",
			frameborder: "0",
			class: "ajaxzoom_iframe",
			scrolling: "no",
			id: $(this).attr("id"),
			allowfullscreen: true,
			// set src of the iframe and add iframeID query string parameter instantly
			src: $(this).attr("data-isrc") + "&iframeID=" + $(this).attr("id")
		});

		$(this).replaceWith(iframe);
	}
});
</script>
							

Two iframes with 360° from http://www.ajax-zoom.com side by side (bootstrap col-sm-6) and use of jQuery lazyload plugin

Please note that older versions of jQuery lazyload plugin do not support iframes! If you already have jQuery lazyload in your template make sure that you have one of the latest versions / update it. A minified version of lazyload plugin which works is included in head of this example file.

Here we use bootstrap "embed-responsive" class for the outer DIV and "embed-responsive-item" bootstrap class for the iframe item. "embed-responsive" is nice when you want to set exact proportions of the div by defining the padding-bottom as the percentage value. Other than one would expect the percentage is calculated out of width of the element... Additionally the class "lazy" to identify the iframes which should be lazy loaded. Note that same as with images the src attribute is not defined. Instead the lazy load plugin uses "data-original" html5 attribute and sets the "src" when the user scrolls the iframe in view.


<div class="embed-responsive" style="padding-bottom: 69%;">
	<iframe
		class="embed-responsive-item lazy"
		width="100%"
		frameborder="0"
		id="ajaxzoom_frame_a1"
		data-original="https://www.ajax-zoom.com/examples/example33_vario.php?3dDir=/pic/zoom3d/Speed_Strength_BlackJacket&fullScreenApi=0&spinReverse=1&mouseScrollEnable=0&spinNoInit=1&iframeID=ajaxzoom_frame_a1"
		scrolling="no"
		allowfullscreen>
	</iframe>
</div>

<script type="text/javascript">
	$("iframe.lazy").lazyload();
</script>
				

Some image (gallery) from https://www.ajax-zoom.com with a border around iframe


<iframe 
	class="ajaxzoom_iframe" 
	width="100%" 
	frameborder="0" 
	id="ajaxzoom_frame_2" 
	src="https://www.ajax-zoom.com/examples/example33_vario.php?zoomDir=trasportation&zoomFile=transportation_007.jpg&mouseScrollEnable=1&iframeID=ajaxzoom_frame_2" 
	scrolling="no" 
	allowfullscreen>
</iframe>

360° spin from https://www.ajax-zoom.com and lazy load


<iframe 
	class="ajaxzoom_iframe lazy" 
	width="100%" 
	frameborder="0" 
	id="ajaxzoom_frame_3" 
	data-original="https://www.ajax-zoom.com/examples/example33_vario.php?3dDir=/pic/zoom3d/Ecco&spinReverse=1&mouseScrollEnable=1&spinNoInit=1&iframeID=ajaxzoom_frame_3" 
	scrolling="no" 
	allowfullscreen>
</iframe>

Local iframe with one image and lazy load


<iframe 
	class="ajaxzoom_iframe lazy" 
	width="100%" 
	frameborder="0" 
	id="ajaxzoom_frame_5" 
	data-original="example33_vario.php?zoomData=/pic/zoom/furniture/furniture_006.jpg&mouseScrollEnable=1&iframeID=ajaxzoom_frame_5" 
	scrolling="no" 
	allowfullscreen>
</iframe>

Comments (0)

Leave a Comment

Looking for a place to add a personal image? Visit www.gravatar.com to get Your own gravatar, a globally-recognized avatar. After you're all setup, your personal image will be attached every time you comment.