javascript - "full-window"幻灯片图片拉伸(stretch)错误

标签 javascript jquery html css

如果你去看我正在制作的幻灯片 here ,您可以看到,如果您调整浏览器窗口的大小,图像会正确调整大小和移动。

...除非您使浏览器窗口的宽度小于一定量(我不知道是什么定义了该量),然后它会拉伸(stretch)图像而不是缩放图像。我该如何解决这个问题?

这是我的调整大小代码:

winWidth = $(window).width();
winHeight = $(window).height();
ratio = winWidth/winHeight;
if(ratio > imgRatio){
    $('#curImg img').css({width:winWidth});
    imgWidth = winWidth;
    imgHeight = $('#curImg img').height();
    $("#curImg img").css({top: (-1*Math.round((imgHeight-winHeight)/2)) + "px"});
    $("#curImg").css({height: winHeight + "px"});
}else{
    $('#curImg img').css({height:winHeight});
    imgHeight = winHeight;
    imgWidth = $('#curImg img').width();
    $("#curImg img").css({left: (-1*Math.round((imgWidth-winWidth)/2)) + "px"});
    $("#curImg").css({width: winWidth + "px"});
}

最佳答案

您还可以查看这个 jQuery 插件: http://srobbin.com/jquery-plugins/backstretch/

或着眼于多种解决方案的 CSS 技巧: http://css-tricks.com/perfect-full-page-background-image/

关于javascript - "full-window"幻灯片图片拉伸(stretch)错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11208519/

相关文章:

javascript - 从任何地方滚动一个 Div

HTML 和 CSS 间距问题

javascript - 在子 div 中滚动(固定)应该滚动父 div

javascript - “Thinking in AngularJS”,如果我有jQuery背景?

javascript - 文本选择(准备使用剪贴板操作)

javascript - 使用 Sticky-kit 粘贴 div 并在 AngularJS 中的特定点释放它

javascript - 仅当使用 jQuery 的 html() 内部存在 <img/> 标记时获取元素内部文本

jquery - 根据 jQuery 中的输入值更改函数

css - div 中的垂直对齐被忽略

javascript - 以前在 Angular 矩js