So i got this gallery script and it works fine , but im trying to import onMousedown function ,so when i click and hold the 'next' or 'previous' links , images just keep changing in a loop ,until i release the link
<html>
<head>
<script type='text/javascript'>
var imageGallery = [
"img1.jpg" ,
"img2.jpg" ,
"img3.jpg",
"img4.jpg"
];
var imgCount = 0;
var totalImgs = imageGallery.length - 1;
function next() {
imgCount++ ;
if(imgCount > totalImgs) imgCount = 0
document.getElementById("gallery").src = imageGallery[imgCount] ;
}
function previous() {
imgCount--;
if(imgCount < 0) imgCount = totalImgs ;
document.getElementById("gallery").src = imageGallery[imgCount] ;
}
</script>
</head>
<body>
<a href="#" onMousedown="next(); return false;">Next</a>
<a href="#" onMousedown="previous(); return false;">Back</a>
<img id="gallery"src="img1.jpg"style="height:420px;width:744px">
</body>
</html>
You can try hooking mousehold in this way:
window.onmouseup
event function clear the intervalConsider to remove inline event bindings..
HTML:
Code:
Demo: http://jsfiddle.net/T42jj/