j查询轮播/图库无法正常工作
jQuery carousel / Gallery not working correctly
我是JS的新手,并且在破解一些问题时遇到了真正的问题,希望有人可以帮助我。
- 图像未变为全尺寸
- 如果您调整大小并单击导航,则会以 100 英里/小时的速度继续前进
- 当您调整大小时,它无法正确调整图像/轮播的大小
- 我尝试添加getImageSize函数来获取更改的图像大小,并且设置 LIS,但这不起作用 以太 币
正如我所说,我非常新,这是一项新工作,所以我真的需要今天完成这项工作:(
.JS:
jQuery(document).ready(function ($) {
//get width of document here and set to li
setConfig();
//getImageSizes();
$(window).resize(function () {
setConfig();
//getImageSizes();
});
var slideCount, slideWidth, slideHeight, sliderULWidth;
function setConfig() {
$('#gallery-slider ul li').css({
"width": ($(window).width() - 200), "height": $(window).height() - 200
});
slideCount = $('#gallery-slider ul li').length;
slideWidth = $('#gallery-slider ul li').width();
slideHeight = $('#gallery-slider ul li').height();
sliderULWidth = slideCount * slideWidth;
$('#gallery-slider').css({
width: slideWidth,
height: slideHeight
});
$('#gallery-slider ul').css({
width: sliderULWidth,
marginLeft: -slideWidth
});
$('#gallery-slider ul li:last-child').prependTo('#gallery-slider ul');
$('#gallery-slider a.control_prev').on('click', function () {
moveLeft();
return false;
});
$('#gallery-slider a.control_next').on('click', function () {
moveRight();
return false;
});
}
function getImageSizes() {
$("#gallery-slider ul li img").each(function () {
var $this = $(this);
$('#gallery-slider ul li').css({ "width": $this.width(), "height": $this.height() });
console.log($this.width());
console.log($this.height());
});
}
function moveLeft() {
$('#gallery-slider ul').animate({
left: +slideWidth
}, 200, function () {
$('#gallery-slider ul li:last-child').prependTo('#gallery-slider ul');
$('#gallery-slider ul').css('left', '');
});
}
function moveRight() {
$('#gallery-slider ul').animate({
right: -slideWidth
}, 200, function () {
$('#gallery-slider ul li:first-child').appendTo('#gallery-slider ul');
$('#gallery-slider ul').css('right', '');
});
}
});
http://codepen.io/anon/pen/MYwPXQ
提前致谢
已修复http://codepen.io/choukroun/pen/OPVBdR
请注意,您在moveright()
left: +slideWidth
在moveleft()
right: -slideWidth
当您使用 2 个方向时会令人困惑,通常最好只使用left/right
为了获得更好的性能,我会建议你使用transform: translate
我不会从头开始编码。有许多jQuery插件(见这里)正是你需要的。例如 http://fotorama.io/就是这样一个插件。请参阅下面的示例。你也可以在这里找到jsFiddle。
另外 galleria.io 是一个很好的画廊滑块。我已经在生产中将其用于较小的网页。
这要容易得多。请查看fotorama页面以进行自定义(例如自动播放,缩略图等)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/fotorama/4.6.2/fotorama.js"></script>
<link href="http://cdnjs.cloudflare.com/ajax/libs/fotorama/4.6.2/fotorama.css" rel="stylesheet" />
<div class="fotorama">
<img src="http://s.fotorama.io/1.jpg" />
<img src="http://s.fotorama.io/2.jpg" />
</div>
相关文章:
- Javascript:selenium Web驱动程序isDisplayed()不工作
- jQuery UI自动完成突然停止工作
- AngularJS UI路由器不能像ng路由器那样工作
- HTML5音频加载和播放获胜'我不能在iPad上工作
- JavaScript打印功能使日历停止工作
- Javascript.getHours()工作不正常
- 为什么这在IE中的工作方式与在Firefox中不同
- 视频HTML没有'无法在Internet Explorer 11上工作
- 扩展移相器按钮类不工作
- Firebase迁移-简单的Firebase.set没有'不再工作了——旧的还是新的
- 谷歌地图不是以HTML显示,而是在JS Fiddle上工作
- 正在尝试使用if和else添加类,但无法正常工作
- Jquery FadeIn FadeOut 只工作一次
- Foreach无法在Typescript中工作
- 另一个ajax调用中的Jquery ajax调用在for循环中没有按预期工作
- 为什么不是't窗口.恢复正常工作吗?(javascript/jquery)
- JS可以在Chrome中工作,但不能在Firefox中工作
- ajaxToolkit PopupControlExtender不工作.过时的
- HTML标记在脚本标记中工作
- javascript扫雷器floodfill算法不能正常工作