我有以下工具提示代码 - 它在 Fx 中完美运行
http://jsfiddle.net/mplungjan/jkCKh/(使用的图像用于演示目的)
代码的目的是没有任何大于或大于 150 像素的东西,并让它在鼠标悬停时显示原始大小。
var imgUrl = "http://c487397.r97.cf2.rackcdn.com/wp-content/uploads/2011/09/TallCat.jpg";
var idx=1;
var imageObject = $('<img/>').load(function(){
var w = this.width;
var h = this.height;
var orgSize = {width:w,height:h};
var imgId = "thumb_"+idx;
var actualImage = $('<img/>')
.attr("id",imgId)
.attr("src",imgUrl)
.addClass("thumb")
.data("orgSize",orgSize);
// set EITHER width OR height if either is > 150
if (w<h && w>150) actualImage.attr("width",150);
else if (w>h && h > 150) actualImage.attr("height",150);
$('.qTip2Image').append(actualImage);
}).attr("src",imgUrl);
var cont_left;
$("img.thumb")
.live("mouseenter",function() {
// save this scaled down image size for later
$(this).data("newSize",{width:this.width,height:this.height})
$(this).animate({
width: $(this).data("orgSize").width,
height: $(this).data("orgSize").height,
left: "-=50",
top: "-=50"
}, "fast");
})
.live("mouseleave",function() {
$(this).animate({
width: $(this).data("newSize").width,
height: $(this).data("newSize").height,
left: "+=50",
top: "+=50"
}, "fast");
});
如何在保持纵横比的同时在大多数浏览器中同样减小尺寸?
如果实际需要计算该比率,请通过发布一个优雅的计算来帮助我。