gpt4 book ai didi

javascript - 图像不会使用 Javascript Image Slider 滑动

转载 作者:行者123 更新时间:2023-11-28 09:59:55 25 4
gpt4 key购买 nike

我正在尝试为婚礼网站创建一个简单的图像 slider 。我已经完成了 html/css/javascript/。我已经下载了 jQuery 并将其链接到我的 HTML 上,但我的图像不会向左或向右滑动。

目前我只有 4 张图片,但想添加更多图片。两个问题: 1) 为什么我的图像没有从左向右滑动。 2) 即使我在 CSS 中将 a img 或 .gallery img 中的宽度更改为 100%,我似乎也无法让我的图像完整显示。

**html:**

<!DOCTYPE HTML>
<HTML>
<head>
<title>Sliding Gallery</title>
<link href="wedgallery.css" rel="stylesheet">
<script type = "text/javascript" "src=/js/jquery.js"></script>
<script type = "text/javascript" "src=/js/script.js"></script>
</head>
<body>
<div class="gallery-wrapper">
<div class="gallery-mask">
<ul class= "gallery-ul">
<li class= "gallery-li">
<img class="gallery-img" src="https://fbcdn-sphotos-g-a.akamaihd.net/hphotos-ak-xfa1/t1.0-9/1374070_730708953622490_1010731455_n.jpg"/>
</li>
<li class= "gallery-li">
<img class="gallery-img" src="https://scontent-a-sea.xx.fbcdn.net/hphotos-xaf1/t1.0-9/10462601_10103161835358498_7988262285040821351_n.jpg"/>
</li>
<li class= "gallery-li">
<img class="gallery-img" src="https://fbcdn-sphotos-c-a.akamaihd.net/hphotos-ak-xfa1/t1.0-9/10403482_10103161834694828_1487443543209476811_n.jpg"/>
</li>
<li class= "gallery-li">
<img class="gallery-img" src="https://scontent-a-sea.xx.fbcdn.net/hphotos-xaf1/t1.0-9/10418946_575487062563825_5057353573068803390_n.jpg"/>
</li>
</ul>
</div>

<div class= "leftbttn">
<div class= "leftbttn-inner">
</div>
</div>
</div>

<div class= "rightbttn">
<div class= "rightbttn-inner">
</div>
</div>
</div>
</body>
</HTML>

**CSS:**

*
{
margin:0px;
padding:0px;
}

a img {
border:none;

}
body {
background:#666;
}

.gallery-wrapper {
width:480px;
height:360px;
margin: 50px auto 0 auto;
border: 3px solid #fff;
position:relative;
}

.gallery-mask {
width:480px;
height:360px;
overflow:hidden;
}

.gallery-ul {
list-style-type: none;
height:360px;
width:auto;
}

.gallery-li {
float:left;
height:360px;
width:480px;
}

.leftbttn {
width:75px;
height:360px;
position:absolute;
top:0px;
left:0px;
background: #666;
opacity:0.2;

}

.rightbttn {
width:75px;
height:360px;
position:absolute;
top:50px;
right:400px;
background: #666;
opacity:0.2;

}


.leftbttn:hover,
.rightbttn:hover {
opacity:0.5;
}

.rightbttn-inner,
.leftbttn-inner {
width:35px;
height:80px;
margin:140px auto 0 auto;


}

.leftbttn-inner {
background-image: url('http://findicons.com/files/icons/2766/app_icons/26/arrow_left.png');
background-repeat: no-repeat;
background-position: 0px 30px;
}

.leftbttn-inner:hover {
background-position: -35px 0;

}

.rightbttn-inner {
background-image: url('http://findicons.com/files/icons/2766/app_icons/26/arrow_right.png');
background-repeat: no-repeat;
background-position: 0px 30px;
}

.rightbttn-inner:hover {
background-position: -35px 0;
}

**Javascript:**

var numImages = 0;

var currentImage = 1;

totalWidth = 0;

$(document).ready( function(){



$('.gallery-li').each( function(){
numImages++;
totalWidth += 480;
});

$('.gallery-ul').css('width' , totalWidth + 'px');

$('rightbttn').click( function(){
moveLeft();
});

$('leftbttn').click( function(){
moveRight();
});

});

function moveLeft() {
if(currentImage < numImages)
{
$('.gallery-ul').animate( {'marginLeft' : '-=480px'} , 1000 , 'swing')
currentImage++;
}
}

function moveRight() {
if(currentImage > 1)
{
$('.gallery-ul').animate( {'marginLeft' : '+=480px'} , 1000 , 'swing')
currentImage--;
}
}

最佳答案

您的代码中有小错误。 查看fiddle

    $('.rightbttn').click(function() {
moveLeft();
});
$('.leftbttn').click(function() {
moveRight();
});

关于javascript - 图像不会使用 Javascript Image Slider 滑动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24750511/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com