CassidyHunt
IS-IT--Management
I have an image scroller that I want to stop the scrolling when the last picture has been displayed in that direction.
Here is the code.
scrollWidth in IE gives me the width of the div so I know where to stop it. Firefox gives me the width of the div as it is displayed, 730.
Any suggestions? I have tried clientWidth, offsetWidth and just Width. They all give me the 730 number in both browsers. That is how I came to scrollWidth and found it worked in IE and not anywhere else.
Any help would be appreciated.
Cassidy
Here is the code.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">[/URL]
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim di As New System.IO.DirectoryInfo(Server.MapPath("Images/staticpics/"))
Dim dt As New System.Data.DataTable
dt.Columns.Add("filename")
For Each fi As System.IO.FileInfo In di.GetFiles
If fi.Extension.ToUpper = ".JPG" Then
Dim nrow As Data.DataRow = dt.NewRow
nrow("filename") = fi.Name
dt.Rows.Add(nrow)
End If
Next
rpPictures.DataSource = dt.DefaultView
rpPictures.DataBind()
End Sub
</script>
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<title>Untitled Page</title>
<style type="text/css">
#clhPicture_pictures img {
border: none;
}
</style>
<script type="text/javascript">
<!--
var timer = null;
var speed = 5; // increase to go faster
var images = new Array();
var startdisplay = 10; // Number to start processing display
var endpos = 0;
function init() {
document.body.parentNode.onmouseup = cancelTimer;
}
function cancelTimer() {
if (timer != null) {
clearInterval(timer);
timer = null;
}
}
function leftScroll(e) {
var scrollDiv = document.getElementById('clhPicture_pictures');
var currentPos = parseInt(scrollDiv.style.left, 10);
if(scrollDiv.offsetLeft < 0) {
scrollDiv.style.left = (currentPos + speed) + 'px';
if (timer == null) timer = setInterval('leftScroll()', 30);
}
}
function rightScroll(e) {
var scrollDiv = document.getElementById('clhPicture_pictures');
var currentPos = parseInt(scrollDiv.style.left, 10);
if(scrollDiv.offsetLeft > (0 - (scrollDiv.scrollWidth - scrollDiv.offsetWidth))) {
scrollDiv.style.left = (currentPos - speed) + 'px';
if (timer == null) timer = setInterval('rightScroll()', 30);
}
}
function addImage(filename) {
images[images.length] = new image(filename,images.length);
if(images.length == startdisplay) {
for(var i=0;i < startdisplay; i++) {
document.getElementById('clhPicture_pictures').appendChild(images[i].tImage);
}
} else {
if(images.length > startdisplay) {
document.getElementById('clhPicture_pictures').appendChild(images[images.length - 1].tImage);
}
}
}
function image(filename,index) {
this.Image = new Image();
this.Image.src = 'thumbnail.aspx?filename=' + filename + '&height=288';
this.tImage = new Image();
this.tImage.src = 'thumbnail.aspx?filename=' + filename + '&height=72';
this.tImage.onclick = function(){ getPicture(index); };
}
function getPicture(index) {
document.getElementById("bigPicture").innerHTML = '';
document.getElementById("bigPicture").appendChild(images[index].Image);
}
//window.onload = init;
//-->
</script>
</head>
<body>
<form name="form1" method="post" action="Default.aspx" id="form1">
<div>
<br />
<table>
<tr>
<td colspan="3" align="center"><div id="bigPicture" /></td>
</tr>
<tr>
<td><input type="button" value="<<" onmousedown='leftScroll()' onmouseup="cancelTimer();" /></td>
<td>
<div id="clhPicture_container" style="width:730px; height:72px; overflow:hidden; position:relative; border: solid 1px black;">
<div id="clhPicture_pictures" style="height:72px; position:relative; left:0px; white-space: nowrap;">
<script type="text/javascript">
<asp:Repeater ID="rpPictures" runat="server">
<ItemTemplate>
addImage('<%# Eval("filename") %>');
</ItemTemplate>
</asp:Repeater>
</script>
</div>
</div>
</td>
<td>
<input type="button" value=">>" onmousedown='rightScroll()' onmouseup="cancelTimer();" />
<input type="button" value="Check" onclick="alert(document.getElementById('clhPicture_pictures').clientWidth);" />
</td>
</tr>
</table>
</form>
</body>
</html>
scrollWidth in IE gives me the width of the div so I know where to stop it. Firefox gives me the width of the div as it is displayed, 730.
Any suggestions? I have tried clientWidth, offsetWidth and just Width. They all give me the 730 number in both browsers. That is how I came to scrollWidth and found it worked in IE and not anywhere else.
Any help would be appreciated.
Cassidy