请教大家一个微博图片效果问题[已经解决]
时间:2010-05-28
来源:互联网
代码:
var w=this.width;var h=this.height;
if( w > maxw){ //图片宽度控制maxw为560像素,除Firefox其他浏览器正常
oldw = w;
w = maxw;
h = parseInt(h * (maxw/oldw));
};
原因已经找到,js代码本身没什么问题,是自己在写css样式的时候没有做到兼容,导致火狐下出现错误,谢谢大家!
[ 本帖最后由 henaxxz 于 2010-5-28 15:14 编辑 ]
作者: henaxxz 发布时间: 2010-05-28

作者: cwq2jxl 发布时间: 2010-05-28
代码:
/*Name: artZoom[图片放大镜]
Version: 1.0.2
Author: tangbin
Email: [email protected]
Website: www.planeArt.cn
*/
(function($){
$.fn.artZoom = function(){
$(this).live('click', function(){
var maxImg = $(this).attr('href'),
viewImg = $(this).attr('rel').length === '0' ? $(this).attr('rel') : maxImg;
if ($(this).find('.loading').length == 0) $(this).append('<span class="loading" title="Loading..">Loading..</span>');
imgTool($(this), maxImg, viewImg);
return false;
});
//图片预先加载
var loadImg = function (url, fn){
var img = new Image();
img.src = url;
if (img.complete){
fn.call(img);
}else{
img.onload = function(){
fn.call(img);
};
};
};
var imgTool = function(on, maxImg, viewImg) {
var width = 0,
height = 0,
tool = function(){
on.find('.loading').remove();
on.hide();
if (on.next('.artZoomBox').length != 0){
return on.next('.artZoomBox').show();
};
var maxWidth = on.parent().width() - 20;
if (width > maxWidth) {
height = maxWidth / width * height;
width = maxWidth;
};
var html = '<div class="artZoomBox"><div class="tool"><a class="hideImg" href="#" title="收起">收起</a><a class="imgLeft" href="#" title="向左转">向左转</a><a class="imgRight" href="#" title="向右转">向右转</a><a class="viewImg" href="' + viewImg + '" title="查看原图">查看原图</a></div><a href="' + viewImg + '" class="maxImgLink"> <img class="maxImg" width="' + width + '" height="' + height + '" src="' + maxImg + '" /></a></div>';
on.after(html);
var box = on.next('.artZoomBox');
box.hover(function(){
box.addClass('js_hover');
}, function(){
box.removeClass('js_hover');
});
box.find('a').bind('click', function(){
//收起
if($(this).attr('class') == 'hideImg' || $(this).attr('class') == 'maxImgLink') {
box.hide();
box.prev().show();
};
//左旋转
if($(this).attr('class') == 'imgLeft') {
box.find('.maxImg').rotate('left')
};
//右旋转
if($(this).attr('class') == 'imgRight') {
box.find('.maxImg').rotate('right')
};
//新窗口打开
if($(this).attr('class') == 'viewImg') window.open(viewImg);
return false;
});
};
loadImg(maxImg, function(){
width = this.width;
height= this.height;
tool();
});
//图片旋转
$.fn.rotate = function(p){
img = $(this)[0];
var n = img.getAttribute('step');
if(n == null) n = 0;
if(p == 'left'){
(n == 3) ? n = 0 : n++;
}else if(p == 'right'){
(n == 0)? n = 3 : n--;
};
img.setAttribute('step', n);
//MSIE
if(document.all) {
img.style.filter = 'progid:DXImageTransform.Microsoft.BasicImage(rotation='+ n +')';
//HACK FOR MSIE 8
switch(n){
case 0:
$(this).next().height = img.height;
break;
case 1:
$(this).next().height = img.width;
break;
case 2:
$(this).next().height = img.height;
break;
case 3:
$(this).next().height = img.width;
break;
}
//DOM
}else{
var c = $(this).next('canvas')[0];
if($(this).next('canvas').length == 0){
$(this).css({'visibility': 'hidden', 'position': 'absolute'});
c = document.createElement('canvas');
c.setAttribute('class', 'maxImg canvas');
img.parentNode.appendChild(c);
}
var canvasContext = c.getContext('2d');
switch(n) {
default :
case 0 :
c.setAttribute('width', img.width);
c.setAttribute('height', img.height);
canvasContext.rotate(0 * Math.PI / 180);
canvasContext.drawImage(img, 0, 0);
break;
case 1 :
c.setAttribute('width', img.height);
c.setAttribute('height', img.width);
canvasContext.rotate(90 * Math.PI / 180);
canvasContext.drawImage(img, 0, -img.height);
break;
case 2 :
c.setAttribute('width', img.width);
c.setAttribute('height', img.height);
canvasContext.rotate(180 * Math.PI / 180);
canvasContext.drawImage(img, -img.width, -img.height);
break;
case 3 :
c.setAttribute('width', img.height);
c.setAttribute('height', img.width);
canvasContext.rotate(270 * Math.PI / 180);
canvasContext.drawImage(img, -img.width, 0);
break;
};
};
};
};
};
)(jQuery);
作者: tangbin1987 发布时间: 2010-05-28
作者: henaxxz 发布时间: 2010-05-28
作者: henaxxz 发布时间: 2010-05-28
[ 本帖最后由 henaxxz 于 2010-5-28 14:13 编辑 ]
作者: henaxxz 发布时间: 2010-05-28
var maxWidth = on.parent().width() - 20;
意思就是获取缩略图父级元素的宽度为大图的最大宽度(再减去了20),而高度不用限制。
作者: tangbin1987 发布时间: 2010-05-28
作者: henaxxz 发布时间: 2010-05-28
作者: shbijiben 发布时间: 2010-05-28
http://www.planeart.cn/downs/artZoom/demo.html
作者: tangbin1987 发布时间: 2010-05-28
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28