OK, iv1 only exists within the scope of the document ready function where it was defined. And in addition, it appears that iv2 is the one you are actually using. It is also of the same limited scope. So, let's first get rid of this from your demo:
Code:
<script>
$(document).keydown(function(e){
switch(e.keyCode){
case 38: {//up arrow
iv1.iviewer('zoom_by', 1);;
break;
}
case 40: {//down arrow
iv1.iviewer('zoom_by', -1);;
break;
}
default: {
return;
}
}
e.preventDefault();
});
</script>
And add the highlighted to it as shown:
Code:
<script type="text/javascript">
var $ = jQuery;
$(document).ready(function(){
var iv1 = $("#viewer").iviewer({
src: "test_image2.png",
update_on_resize: false,
zoom_animation: false,
mousewheel: false,
onMouseMove: function(ev, coords) { },
onStartDrag: function(ev, coords) { return false; }, //this image will not be dragged
onDrag: function(ev, coords) { }
});
$("#in").click(function(){ iv1.iviewer('zoom_by', 1); });
$("#out").click(function(){ iv1.iviewer('zoom_by', -1); });
$("#fit").click(function(){ iv1.iviewer('fit'); });
$("#orig").click(function(){ iv1.iviewer('set_zoom', 300); });
$("#update").click(function(){ iv1.iviewer('update_container_info'); });
var iv2 = $("#viewer2").iviewer(
{
src: "test_image2.png"
});
$("#chimg").click(function()
{
iv2.iviewer('loadImage', "test_image2.png");
return false;
});
$(document).keydown(function(e){
switch(e.keyCode){
case 38: {//up arrow
iv2.iviewer('zoom_by', 1);;
break;
}
case 40: {//down arrow
iv2.iviewer('zoom_by', -1);;
break;
}
default: {
return;
}
}
e.preventDefault();
});
});
</script>
The browser cache may need to be cleared, and/or the page reloaded to see changes.
Any questions or problems, just let me know.
Bookmarks