gpt4 book ai didi

javascript - 试图让 scrollTo 水平工作

转载 作者:太空宇宙 更新时间:2023-11-04 16:20:48 25 4
gpt4 key购买 nike

我试图让 jQuery scrollTo 插件水平工作,所以我整理了一些 jsfiddle。

http://jsfiddle.net/P9B5y/15/

现在,在没有 javascript 的情况下,它只是替换每个图像(img 1、img 2 等),但是一旦启动 jQuery,它就不会触发。

如有任何帮助,我们将不胜感激!

最佳答案

根据您的评论:

I would live each id="image#" to scroll horizontally, and replace, rather than just replacing. Like so; jsfiddle.net/P9B5y, except there would be a cut-off, that would only allow one id to be shown at one particular time, as oppose to some waiting

我不相信 scrollTo 插件是您想要的。我相信你想要的是创建一个视口(viewport),并在视口(viewport)后面为列表设置动画,就像这样 http://jsfiddle.net/7SLrL/1/ :

HTML:

<div id="viewport">
<ul>
<li>
<img src="http://www.digital-photography-school.com/wp-content/uploads/2007/11/flower.jpg" />
</li>
<li>
<img src="http://media2.teenormous.com/items/www.uneetee.com/product_images-d-775-HiddenAnimals__39659_std.jpg" />
</li>
<li>
<img src="http://media1.teenormous.com/items/media.80stees.com/images-products-Ladies-Slim-Fit-Animal-Shirt.jpg" />
</li>
<li>
<img src="http://astorenet.com/wp-content/uploads/2011/04/wpid-67-petrol-rc-car.jpg" />
</li>
</ul>
</div>

<div id="nav">
<ul>
<li>
<img src="http://www.digital-photography-school.com/wp-content/uploads/2007/11/flower.jpg" />
</li>
<li>
<img src="http://media2.teenormous.com/items/www.uneetee.com/product_images-d-775-HiddenAnimals__39659_std.jpg" />
</li>
<li>
<img src="http://media1.teenormous.com/items/media.80stees.com/images-products-Ladies-Slim-Fit-Animal-Shirt.jpg" />
</li>
<li>
<img src="http://astorenet.com/wp-content/uploads/2011/04/wpid-67-petrol-rc-car.jpg" />
</li>
</ul>
</div>

JQuery

$('#nav li').click(function(){
var _this = $(this);
$('#viewport ul').animate({
left: -1* _this.index() * $('#viewport ul li').eq(_this.index()).children('img').width()
},500);
});

CSS:

#viewport {
width:350px;
height:350px;
overflow:hidden;
margin-bottom:10px;
border:1px solid #000;
}

#nav {
width:350px;
height:40px;
}

#viewport ul {
padding:0;
margin:0;
width:1400px; /* 350px per photo * 4 photos*/
position:relative;
}

#viewport img {
width:350px;
height:350px;
}

#nav img {
width:40px;
height:40px;
cursor:pointer;
}

li {
float:left;
}

关于javascript - 试图让 scrollTo 水平工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6638636/

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