- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在制作我的摄影作品集展示/画廊 slider 。
我已经有了一半工作的原型(prototype),但我终生无法弄清楚为什么它在一个方向上完美地居中图像而不是另一个方向:S
有趣的是,如果我调整窗口大小并第二次调用我的 move_slide() 函数,它会转到正确的位置...那么发生了什么?任何人都可以阐明吗?
我认为这是一个非常古怪的问题。所以一双新鲜的眼睛可以帮助我分配。
到目前为止我的代码:
jQuery(window).load(function() {
//
function set_slide_width(add_extra) {
if (!add_extra) {add_extra = 0;}
var slide_width = 0;
$("#barely_slide article img").each(function(){
slide_width += $(this).outerWidth();
});
$("#barely_slide article").css("width",slide_width + add_extra);
}
//
set_slide_width();
//
function move_slide() {
var focus_margin = 0;
var img_real_height = 0;
//
var add_extra = 0;
//var prev_deduct = 0;
//
$("#barely_slide article img").each(function(){
//
//if ($(this).attr("class") == "previous") {
// var theImage = new Image();
// theImage.src = $(this).attr("src");
// var img_real_width = theImage.width;
// var img_real_width_padding = img_real_width + ($(this).outerWidth() - $(this).width());
// prev_deduct = img_real_width_padding - $(this).outerWidth();
//}
//
if ($(this).attr("class") == "focus") {
var theImage = new Image();
theImage.src = $(this).attr("src");
var img_real_width = theImage.width;
var img_real_width_padding = img_real_width + ($(this).outerWidth() - $(this).width());
img_real_height = theImage.height;
//
add_extra = img_real_width_padding - $(this).outerWidth();
//
focus_margin += img_real_width_padding / 2;
return false;
}
focus_margin += $(this).outerWidth();
});
//
set_slide_width(add_extra);
//
var container_center = $("#barely_slide").outerWidth() / 2;
var offset = container_center - focus_margin;
//console.dir(offset);
$("#barely_slide article").animate({"margin-left": offset }, "fast");
//
var img_height_offset = (img_real_height / 2) - 150;
$(".focus").animate({"height":img_real_height,"margin-top":-img_height_offset}, "fast");
}
//
move_slide();
//
var resize_timeout;
$(window).resize(function() {
clearTimeout(resize_timeout);
resize_timeout = setTimeout(function(){
move_slide();
},100);
});
//
$("#barely_slide article img").on("click", function(){
if ($(this).attr("class") == "focus") {return false;}
//
$("#barely_slide article img").removeClass("previous");
$("#barely_slide article .focus").addClass("previous");
$(".previous").animate({"height":300,"margin-top":0}, "fast");
//
$("#barely_slide article .focus").removeClass("focus");
$(this).addClass("focus");
move_slide();
return false;
});
});
最佳答案
我找到了另一个效果更好的解决方案。您只需更改为 move_slide
函数:
function move_slide() {
var focus_margin = 0;
var img_real_height = 0;
var add_extra = 0;
$("#barely_slide article img").each(function(){
if ($(this).hasClass("focus")) {
var theImage = new Image();
theImage.src = $(this).attr("src");
var img_real_width = theImage.width;
var img_real_width_padding = img_real_width + ($(this).outerWidth() - $(this).width());
img_real_height = theImage.height;
add_extra = img_real_width_padding - $(this).outerWidth();
focus_margin += img_real_width_padding / 2;
return false;
/***************** This is where the changes begin *************************/
} else if ($(this).hasClass("previous")) {
// If has the previous class, calculate the width with a height of 300.
var shrinked_width = 300 * $(this).width() / $(this).height();
// add the padding.
var img_width_width_padding = shrinked_width + ($(this).outerWidth() - $(this).width());
// then update the focus_margin
focus_margin += img_width_width_padding;
} else {
focus_margin += $(this).outerWidth();
}
/***************** This is where the changes end ***************************/
});
set_slide_width(add_extra);
var container_center = $("#barely_slide").outerWidth() / 2;
var offset = container_center - focus_margin;
$("#barely_slide article").animate({"margin-left": offset }, "fast");
var img_height_offset = (img_real_height / 2) - 150;
$(".focus").animate({"height":img_real_height,"margin-top":-img_height_offset}, "fast");
}
这是 jsfiddle:http://jsfiddle.net/JQaLB/4/
关于javascript - Jquery 图像 slider 从右到左完美工作,但从左到右我无法使其居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16212552/
为了加速测试字谜字符串的快速输出行为,我 came up with基于质数的哈希方案——尽管它看起来像 I wasn't the first . 基本思想是将字母映射到素数,并计算这些素数的乘积。字母
我使用 Perfect Framework 创建了一个 Swift 3.0 服务器。一切都按预期进行得很好,但我正在尝试了解是否有更好的方法来做一些事情。 来自 iOS 背景,我知道总是在不同的线程中
我有一个固定大小的正方形 div,希望使用 CSS 在其中放置任意大小的图像,以便它在水平和垂直方向上都居中。横向很容易: .container { text-align: center } 对于垂直
程序员离不开终端,配置一个好看又好用的终端,可以提高工作效率. 本篇文章记录了使用 Oh My Zsh + PowerLevel9k + zsh插件 快速配置Ubuntu下默认终端的过程. 我们在
在请求处理程序中,处理例如获取 https://example.com/collections/1或 POSThttp://0.0.0.0:8080/collections 如何获取服务器地址 htt
我正在使用 perfect 和 SQLite司机和StORM作为连接器。我可以一一保存(创建)多行。为了使其更快,我想一次创建多行,我该怎么做? 最佳答案 从完美的 SQLite-StORM 和 Pe
这是我在这里的第一篇文章,所以我希望我提供所有正确的信息。 我目前正在开发一个简单的菜单应用程序,它有一个按钮控制数组(使用 MSDN 建议的控制数组的变通方法),我很难重新调整表单大小和将按钮居中。
在 androidplot XYPlot 中,如果您有较大的值(许多数字)和/或较大的字体大小,则 Y 轴上的刻度标签会被剪裁。这个(以及 X 轴上的类似问题)之前已经在这些问题中讨论过: Range
注意:我遗漏了不相关的代码 所以我目前正在研究 CCC 1996 P1,这个问题的全部目的是能够计算一个整数输入是完美数、不足数还是充数。我上面列出的代码可以工作,但是我认为它太慢了。该代码会迭代每个
我需要什么 我需要一个产生双射输出的算法。我有一个 31 位输入,需要一个伪随机 31 位输出。 我考虑过的 CRC 在其位宽内是双射的。 我查看了 Google 并找到了多项式,但找不到表格或算法。
我在 Ubuntu 14.04.1、clang-3.8 上使用 PerfectSwift我使用的是 Perfect,一切正常,但现在,我不能再编译了(但它可以在我的 mac 上编译) 错误日志是 /h
如果您对分表有以下痛点那么不妨试试我这边开源的框架sharding-core ,是否需要无感知使用分表组件,是否需要支持abp,是否需要支持自定义分表规则,是否需要支持自定义分表键,是否需要支持特定
我正在尝试确定我的 crc 与“ 理想 ”32 位 crc 的比较。 因此,我运行我的 crc 超过 100 万个完全随机的数据样本并收集了碰撞数量,我想将此数字与我可以从“ 理想 ”crc 中预期的
我正在开发一个项目,需要验证我的 URL,并偶然发现了以下正则表达式模式; /(((http|ftp|https):\/{2})+(([0-9a-z_-]+\.)+(aero|asia|biz|cat
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 4 年前。 Improve
我正在创建一个需要居中于中间的圆形网站。背景由围绕中心图像的圆圈组成。每当我以全屏(F11 快捷键)查看我的网站时,无论我的屏幕分辨率如何,它都完美居中。 如果我在没有全屏显示的情况下查看我的网站,我
所以我有一个网站,在开发人员工具中测试响应能力时看起来很棒,但在 iPhone 本身上实际测试时却没有居中并且看起来有些破烂。 什么会导致这种情况,如果我无法使用 iPhone(在我的 android
我有一个内部类,它扩展了 AbstractTableModel。 import javax.swing.table.AbstractTableModel; public class MyClass e
所以我正在使用 Perfect 服务器开发一个将值返回给客户端的应用程序。目前,它需要从另一个 API 下载一些数据,对其进行处理,然后将其发送给客户端。 然而,出于某种原因,它在 OSX 中编译良好
我有一些 CSS 按钮。 “按钮”效果是通过在 anchor 标记中使用固定大小的 元素来完成的,并且 css 规则以 a span:active 、 a span:hover 的形式显示按钮状态。
我是一名优秀的程序员,十分优秀!