...

View Full Version : Flash to Javascript...



rossmac
08-22-2010, 03:00 PM
Hi there,

A client of mine has asked me to change a flash component on his website to something that will work on the ipad/iphone etc. So my guess is that a javascript created slideshow would do the trick. Check out what I am meaning on this page:

http://www.it-world.com.au/

It's the flash with "Our Services" "Our Products" "Contact" in it.

Can anyone suggest a very easy javascript that I could manipulate to give this same scrolling effect on the click of a link. It needs to be very easy to make changes to as I have no js skills whatsoever other than copying, pasting and making minor changes to obvious pieces of script.

hope someone can help!

Thanks,
Ross

johnmerlino
08-22-2010, 03:06 PM
Scrollers are all over the place:
http://flowplayer.org/tools/scrollable/index.html
http://www.maaki.com/thomas/SmoothDivScroll/

I highly recommend against Flash. JavaScript will persist when Flash perishes.

vwphillips
08-22-2010, 05:13 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
<style type="text/css">
/*<![CDATA[*/
#imgdiv {
position:relative;overflow:hidden;width:600px;height:150px;border:solid black 1px;
}
#imgdiv UL{
position:absolute;left:0px;top:0px;
list-style: none;
border:0;
margin:0;
padding:0;
}

#imgdiv UL IMG {
width:600px;height:150px;
}


/*]]>*/
</style>
<script type="text/javascript">
// Animate (11-January-2010)
// by Vic Phillips http://www.vicsjavascripts.org.uk

// To progressively change the Left, Top, Width, Height or Opacity of an element over a specified period of time.
// With the ability to scale the effect time on specified minimum/maximum values
// and with three types of progression 'sin' and 'cos' and liner.

// **** Application Notes

// **** The HTML Code
//
// when moving an element the inline or class rule style position of the element should be assigned as
// 'position:relative;' or 'position:absolute;'
//
// The element would normally be assigned a unique ID name.
//

// **** Initialising the Script.
//
// The script is initialised by assigning an instance of the script to a variable.
// e.g A = new zxcAnimate('left','id1')
// where:
// A = a global variable (variable)
// parameter 0 = the mode(see Note 1). (string)
// parameter 1 = the unique ID name or element object. (string or element object)
// parameter 1 = the initial value. (digits, default = 0)

// **** Executing the Effect
//
// The effect is executed by an event call to function 'A.animate(10,800 ,5000,[10,800]);'
// where:
// A = the global referencing the script instance. (variable)
// parameter 0 = the start value. (digits, for opacity minimum 0, maximum 100)
// parameter 1 = the finish value. (digits, for opacity minimum 0, maximum 100)
// parameter 2 = period of time between the start and finish of the effect in milliseconds. (digits or defaults to previous or 0(on first call) milliSeconds)
// parameter 3 = (optional) to scale the effect time on a specified minimum/maximum. (array, see Note 3)
// field 0 the minimum value. (digits)
// field 1 the maximum value. (digits)
// parameter 3 = (optional) the type of progression, 'sin', 'cos' or 'liner'. (string, default = 'liner')
// 'sin' progression starts fast and ends slow.
// 'cos' progression starts slow and ends fast.
//
// Note 1: Examples modes: 'left', 'top', 'width', 'height', 'opacity.
// Note 2: The default units(excepting opacity) are 'px'.
// For hyphenated modes, the first character after the hyphen must be upper case, all others lower case.
// Note 3: The scale is of particular use when re-calling the effect
// in mid progression to retain an constant rate of progression.
// Note 4: The current effect value is recorded in A.data[0].
// Note 5: A function may be called on completion of the effect by assigning the function
// to the animator intance property .Complete.
// e.g. [instance].Complete=function(){ alert(this.data[0]); };
//



// **** Functional Code(1.52K) - NO NEED to Change

function zxcAnimate(mde,obj,srt){
this.to=null;
this.obj=typeof(obj)=='object'?obj:document.getElementById(obj);
this.mde=mde.replace(/\W/g,'');
this.data=[srt||0];
return this;
}

zxcAnimate.prototype={

animate:function(srt,fin,ms,scale,c){
clearTimeout(this.to);
this.time=ms||this.time||0;
this.neg=srt<0||fin<0;
this.data=[srt,srt,fin];
this.mS=this.time*(!scale?1:Math.abs((fin-srt)/(scale[1]-scale[0])));
this.c=typeof(c)=='string'?c.charAt(0).toLowerCase():this.c?this.c:'';
this.inc=Math.PI/(2*this.mS);
this.srttime=new Date().getTime();
this.cng();
},

cng:function(){
var oop=this,ms=new Date().getTime()-this.srttime;
this.data[0]=(this.c=='s')?(this.data[2]-this.data[1])*Math.sin(this.inc*ms)+this.data[1]:(this.c=='c')?this.data[2]-(this.data[2]-this.data[1])*Math.cos(this.inc*ms):(this.data[2]-this.data[1])/this.mS*ms+this.data[1];
this.apply();
if (ms<this.mS) this.to=setTimeout(function(){oop.cng()},10);
else {
this.data[0]=this.data[2];
this.apply();
if (this.Complete) this.Complete(this);
}
},

apply:function(){
if (isFinite(this.data[0])){
if (this.data[0]<0&&!this.neg) this.data[0]=0;
if (this.mde!='opacity') this.obj.style[this.mde]=Math.floor(this.data[0])+'px';
else zxcOpacity(this.obj,this.data[0]);
}
}

}

function zxcOpacity(obj,opc){
if (opc<0||opc>100) return;
obj.style.filter='alpha(opacity='+opc+')';
obj.style.opacity=obj.style.MozOpacity=obj.style.WebkitOpacity=obj.style.KhtmlOpacity=opc/100-.001;
}


</script>


</head>

<body>
<div id="imgdiv">
<ul>
<li><a><img src="http://www.vicsjavascripts.org.uk/StdImages/Zero.gif" /></a></li>
<li><a><img src="http://www.vicsjavascripts.org.uk/StdImages/One.gif" /></a></li>
<li><a><img src="http://www.vicsjavascripts.org.uk/StdImages/Two.gif" /></a></li>
<li><a><img src="http://www.vicsjavascripts.org.uk/StdImages/Three.gif" /></a></li>
</ul>
</div>
<a href="javascript:M.GoTo(0);">Goto 0</a>
<a href="javascript:M.GoTo(1);">Goto 1</a>
<a href="javascript:M.GoTo(2);">Goto 2</a>
<a href="javascript:M.GoTo(3);">Goto 3</a>
<script type="text/javascript">
/*<![CDATA[*/

function GoTo(o){
var ul=document.getElementById(o.ID).getElementsByTagName('UL')[0];
this.lis=ul.getElementsByTagName('LI')
this.oop=new zxcAnimate('top',ul,0);
this.ms=o.Duration||1000;
}

GoTo.prototype.GoTo=function(nu){
if (this.lis[nu]){
this.oop.animate(this.oop.data[0],-this.lis[nu].offsetTop,this.ms,[0,this.lis[nu].offsetHeight]);
}
}

var M=new GoTo({
ID:'imgdiv',
Duration:500
});
/*]]>*/
</script>
</body>

</html>

rossmac
08-23-2010, 07:24 AM
Thanks for the links johnmerlino, and thanks especially to vwphillips- this code was exactly what I was needing! I've managed to implement it and get it working beautifully! Have a look...

http://www.it-world.com.au/index_jsmenu.html

Thanks again, much appreciated!

Ross

vwphillips
08-23-2010, 12:44 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
<link href="http://www.it-world.com.au/itw.css1" rel="stylesheet" type="text/css" />
<style type="text/css">
/*<![CDATA[*/
.imgdiv {
position:relative;width:870px;height:204px;border:solid black 1px;
}

#imgdiv {
position:relative;overflow:hidden;width:660px;height:204px;border:solid black 0px;
}
#imgdiv UL{
position:absolute;left:0px;top:0px;
list-style: none;
border:0;
margin:0;
padding:0;
}

#imgdiv UL IMG {
width:660px;
}

#imgdiv_links{
position:absolute;left:660px;top:0px;
}

#mark {
position:absolute;left:-22px;top:19px;width:20px;height:35px;background-Color:red;

}

/*]]>*/
</style>
<script type="text/javascript">
// Animate (11-January-2010)
// by Vic Phillips http://www.vicsjavascripts.org.uk

// To progressively change the Left, Top, Width, Height or Opacity of an element over a specified period of time.
// With the ability to scale the effect time on specified minimum/maximum values
// and with three types of progression 'sin' and 'cos' and liner.

// **** Application Notes

// **** The HTML Code
//
// when moving an element the inline or class rule style position of the element should be assigned as
// 'position:relative;' or 'position:absolute;'
//
// The element would normally be assigned a unique ID name.
//

// **** Initialising the Script.
//
// The script is initialised by assigning an instance of the script to a variable.
// e.g A = new zxcAnimate('left','id1')
// where:
// A = a global variable (variable)
// parameter 0 = the mode(see Note 1). (string)
// parameter 1 = the unique ID name or element object. (string or element object)
// parameter 1 = the initial value. (digits, default = 0)

// **** Executing the Effect
//
// The effect is executed by an event call to function 'A.animate(10,800 ,5000,[10,800]);'
// where:
// A = the global referencing the script instance. (variable)
// parameter 0 = the start value. (digits, for opacity minimum 0, maximum 100)
// parameter 1 = the finish value. (digits, for opacity minimum 0, maximum 100)
// parameter 2 = period of time between the start and finish of the effect in milliseconds. (digits or defaults to previous or 0(on first call) milliSeconds)
// parameter 3 = (optional) to scale the effect time on a specified minimum/maximum. (array, see Note 3)
// field 0 the minimum value. (digits)
// field 1 the maximum value. (digits)
// parameter 3 = (optional) the type of progression, 'sin', 'cos' or 'liner'. (string, default = 'liner')
// 'sin' progression starts fast and ends slow.
// 'cos' progression starts slow and ends fast.
//
// Note 1: Examples modes: 'left', 'top', 'width', 'height', 'opacity.
// Note 2: The default units(excepting opacity) are 'px'.
// For hyphenated modes, the first character after the hyphen must be upper case, all others lower case.
// Note 3: The scale is of particular use when re-calling the effect
// in mid progression to retain an constant rate of progression.
// Note 4: The current effect value is recorded in A.data[0].
// Note 5: A function may be called on completion of the effect by assigning the function
// to the animator intance property .Complete.
// e.g. [instance].Complete=function(){ alert(this.data[0]); };
//



// **** Functional Code(1.52K) - NO NEED to Change

function zxcAnimate(mde,obj,srt){
this.to=null;
this.obj=typeof(obj)=='object'?obj:document.getElementById(obj);
this.mde=mde.replace(/\W/g,'');
this.data=[srt||0];
return this;
}

zxcAnimate.prototype={

animate:function(srt,fin,ms,scale,c){
clearTimeout(this.to);
this.time=ms||this.time||0;
this.neg=srt<0||fin<0;
this.data=[srt,srt,fin];
this.mS=this.time*(!scale?1:Math.abs((fin-srt)/(scale[1]-scale[0])));
this.c=typeof(c)=='string'?c.charAt(0).toLowerCase():this.c?this.c:'';
this.inc=Math.PI/(2*this.mS);
this.srttime=new Date().getTime();
this.cng();
},

cng:function(){
var oop=this,ms=new Date().getTime()-this.srttime;
this.data[0]=(this.c=='s')?(this.data[2]-this.data[1])*Math.sin(this.inc*ms)+this.data[1]:(this.c=='c')?this.data[2]-(this.data[2]-this.data[1])*Math.cos(this.inc*ms):(this.data[2]-this.data[1])/this.mS*ms+this.data[1];
this.apply();
if (ms<this.mS) this.to=setTimeout(function(){oop.cng()},10);
else {
this.data[0]=this.data[2];
this.apply();
if (this.Complete) this.Complete(this);
}
},

apply:function(){
if (isFinite(this.data[0])){
if (this.data[0]<0&&!this.neg) this.data[0]=0;
if (this.mde!='opacity') this.obj.style[this.mde]=Math.floor(this.data[0])+'px';
else zxcOpacity(this.obj,this.data[0]);
}
}

}

function zxcOpacity(obj,opc){
if (opc<0||opc>100) return;
obj.style.filter='alpha(opacity='+opc+')';
obj.style.opacity=obj.style.MozOpacity=obj.style.WebkitOpacity=obj.style.KhtmlOpacity=opc/100-.001;
}


</script>


</head>

<body>
<div class="imgdiv">
<div id="imgdiv">

<ul>
<li><a><img src="http://www.it-world.com.au/images/menu/menu_main01.jpg" width="660" height="204" /></a></li>
<li><a><img src="http://www.it-world.com.au/images/menu/menu_main02.jpg" /></a></li>
<li><a><img src="http://www.it-world.com.au/images/menu/menu_main03.jpg" /></a></li>
</ul>
</div>
<div id="imgdiv_links">
<img src="http://www.it-world.com.au/images/menu/menuright.jpg" alt="menu_items" width="210" height="204" border="0" usemap="#Map" />

<div id="mark" ></div>
<map name="Map" id="Map">
<area shape="rect" coords="1,19,179,51" onclick="M.GoTo(0);showDiv('services1'); hideDiv('text'); hideDiv('products1'); hideDiv('contact1');" />
<area shape="rect" coords="-3,82,176,117" onclick="M.GoTo(1);showDiv('products1'); hideDiv('text'); hideDiv('services1'); hideDiv('contact1');"/>
<area shape="rect" coords="0,146,167,180" onclick="M.GoTo(2);showDiv('contact1'); hideDiv('text'); hideDiv('products1'); hideDiv('services1');"/>
</map>

</div>
</div>
<script type="text/javascript">
/*<![CDATA[*/

function GoTo(o){
var ul=document.getElementById(o.ID).getElementsByTagName('UL')[0];
this.lis=ul.getElementsByTagName('LI')
this.oop=new zxcAnimate('top',ul,0);
this.ms=o.Duration||1000;
var map=document.getElementById(o.MapID);
this.areas=map.getElementsByTagName('AREA');
this.mark=new zxcAnimate('top',o.MarkID,this.areas[0].coords.split(',')[1]*1);
this.GoTo(0);
}

GoTo.prototype.GoTo=function(nu){
if (this.lis[nu]){
this.oop.animate(this.oop.data[0],-this.lis[nu].offsetTop,this.ms,[0,this.lis[nu].offsetHeight]);
this.mark.animate(this.mark.data[0],this.areas[nu].coords.split(',')[1]*1,this.ms);
}
}

var M=new GoTo({
ID:'imgdiv',
Duration:250,
MapID:'Map',
MarkID:'mark'
});

/*]]>*/
</script>
<script type="text/javascript">
/*<![CDATA[*/
function showDiv(){
}
function hideDiv(){
}
/*]]>*/
</script>
</body>

</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum