考虑到导航栏的可用空间,我创建了此代码以调整照片/图像的大小以适应屏幕.
该脚本将在图像加载和导航点击时触发.
有没有人建议改善这一点并确保浏览器兼容性?
$(document).ready(function(){
$("#photo").load(function(){
resize();
});
$(".navigation img").click(function(){
var imgPath = $(this).attr("src");
$("#photo").attr({ src: imgPath });
resize();
return false;
});
});
Run Code Online (Sandbox Code Playgroud)
resize = function() {
var borderVt=150; //value based on css style. bottom bar + padding of photoContain
var borderHz=40; //value based on css style photoContain padding
$("#photo").css("width", "auto").css("height", "auto"); // Remove existing CSS
$("#photo").removeAttr("width").removeAttr("height"); // Remove HTML attributes
var origSizeW = $("#photo").width();
var origSizeH = $("#photo").height();
var ratioVt=(origSizeW/origSizeH);
var ratioHz=(origSizeH/origSizeW);
var winW = $(window).width();
var winH …
Run Code Online (Sandbox Code Playgroud)