There are many ways to approach this, depending on whether you don't wish to give each IMG any ID attribute period, or that you simply don't want to have to manually declare them inside Drag.init() each time. Assuming the former, one way is to just assign images on the page you wish to be draggable a specific CSS class name, for example, "drag, and have the script dynamically scan and make them all draggable:
Code:
<img src="test.gif" class="drag" style="position: relative;" />
<img src="test.gif" class="drag" style="position: relative;" />
<img src="test.gif" class="drag" style="position: relative;" />
<img src="test.gif" style="position: relative;" />
<script type="text/javascript">
var allimages=document.getElementsByTagName("img")
for (var i=0; i<allimages.length; i++){
if (/drag/i.test(allimages[i].className)) //if image contains "drag" CSS class name
Drag.init(allimages[i])
}
</script>
Regarding page load, it simply means wrapping the initializtion code in window.onload:
Code:
<script type="text/javascript">
window.onload=function(){
var allimages=document.getElementsByTagName("img")
for (var i=0; i<allimages.length; i++){
if (/drag/i.test(allimages[i].className)) //if image contains "drag" CSS class name
Drag.init(allimages[i])
}
}
</script>
Bookmarks