Support Forum Softcomplex logo
About Us  | Services  | Download  | Order  | Support  | |
| Search | Today's Posts | Stats | Board Rules | Not logged in [ Login | Register ]
go to bottom
Last active: Never

Printable Version | Subscribe | Add to Favourites   Post new thread Poll:
Author: Subject: Starting from a div
Beef
Newbie

Posts: 1
Registered: 6/29/2007
Member Is Offline
posted on 6/29/2007 at 09:50 PM Reply With Quote
Starting from a div


Hi,

I thought others might be interested in the change I made to the slider.js.

Basically I wanted to have all my Javascript in an external file (no inline) so I changed function slider() so it takes a div id. I also changed it so it would take the height and width from the source div if you don't provide n_controlWidth or n_controlHeight.

You call it as follows:
<div style="width:100px;height:100px" id="MyDiv"></div>
<form name="MyForm"><input type="text" name="MyInput" /></form>
<script>
new slider({
's_divid','MyDiv',
's_form,'MyForm',
........
});
</script>

I have only done minimal testing (FF 2.0 and IE 6) so you may want to test it before putting it on a live server.

To modify the slider() function replace the document.write()

<del>
// generate the control's HTML
document.write(
'<div style="width:' + this.n_controlWidth + 'px;height:' + this.n_controlHeight + 'px;border:0; background-image:url(' + this.s_imgControl + ')" id="sl' + this.n_id + 'base">' +
'<img src="' + this.s_imgSlider + '" width="' + this.n_sliderWidth + '" height="' + this.n_sliderHeight + '" border="0" style="position:relative;left:' + this.n_pathLeft + 'px;top:' + this.n_pathTop + 'px;z-index:' + this.n_zIndex + ';cursor:hand;visibility:hidden;" name="sl' + this.n_id + 'slider" id="sl' + this.n_id + 'slider" onmousedown="return f_sliderMouseDown(' + this.n_id + ')"/></div>'
);
</del>

lines in slider() with:

<replace>
/* Take over the div */
this.e_sourcediv = get_element(this.s_divid);
if(!this.n_controlWidth)
this.n_controlWidth=parseInt(this.e_sourcediv.style.width,10);
if(!this.n_controlHeight)
this.n_controlHeight=parseInt(this.e_sourcediv.style.height,10);
var workingdiv=document.createElement("div");
workingdiv.style.width=this.n_controlWidth+'px';
workingdiv.style.height=this.n_controlHeight+'px';
workingdiv.style.border=0;
workingdiv.style.backgroundImage="url("+this.s_imgControl+")";
workingdiv.id="sl"+this.n_id+"base";

var workingimg=document.createElement("img");
workingimg.src=this.s_imgSlider;
workingimg.width=this.n_sliderWidth;
workingimg.height=this.n_sliderHeight;
workingimg.border=0;
workingimg.style.position="relative";
workingimg.style.left=this.n_pathLeft + "px";
workingimg.style.top=this.n_pathTop + "px";
workingimg.style.zIndex=this.n_zIndex;
// workingimg.style.cursor="pointer"; // didn't like the hand
workingimg.style.visibility="hidden";
workingimg.name="sl" + this.n_id + "slider";
workingimg.id="sl" + this.n_id + "slider";
workingimg.setAttribute("n_id",this.n_id);
workingimg.onmousedown=function(){return f_sliderMouseDown(this.getAttribute("n_id"))};

workingdiv.appendChild(workingimg);

this.e_sourcediv.appendChild(workingdiv);
</replace>
View User's Profile View All Posts By User U2U Member
chitgoks
Newbie

Posts: 1
Registered: 9/7/2007
Member Is Offline
posted on 9/7/2007 at 08:43 AM Reply With Quote

hi, can you give a working sample when using div? i did your instructions but the script seemed to run endlessly..
View User's Profile View All Posts By User U2U Member
Post new thread Poll:

Related Links:
Product Page
Product Demonstrations Live Demos
Multiple Designs
Equalizer
Free Download Free Download
Product Documentation Documentation:
Documentation Page
Change Log
Support Forum Support Forum

Go To Top


Powered by XMB 1.9.1 Nexus
Developed By Aventure Media & The XMB Group © 2002-2004