gpt4 book ai didi

JQuery Scroll Top my image when onmousever

转载 作者:行者123 更新时间:2023-11-28 05:51:25 24 4
gpt4 key购买 nike

我想在鼠标悬停在照片上时滚动照片。我有一个代码,但我不知道该怎么做。请帮助我。

This is my jquery code,

$('.arrow').on('click', function(){
var gallery = $('#image_container');
var height = gallery.height();
var up = $(this).is('.up_arrow');

if (up) {
gallery.animate({'scrollTop': '-=' + height});
} else {
gallery.animate({'scrollTop': '+=' + height});
}
});


and html is listed below,
<div class="arrow up_arrow"><img src="images/icons/circle.gif"></div>
<div id="image_container" >
<p id="text_header" > Back to Green</p>
<img src="images/wallpapers_scroll/1.jpg" />
<img src="images/wallpapers_scroll/2.jpg" />


</div>
<div class="arrow down_arrow"><img src="images/icons/circle.gif"></div>
The #image_container contains the photos

最佳答案

尝试使用 marginTop 而不是 scrollTop。另外,你需要在 height-to-scroll 之后添加 px

$('.arrow').on('click', function(){
var gallery = $('#image_container');
var height = gallery.height();
var up = $(this).is('.up_arrow');

if (up) {
gallery.animate({'marginTop': '-=' + height+'px'},700);
} else {
gallery.animate({'marginTop': '+=' + height+'px'});
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>

<div class="arrow up_arrow"><img src="http://placekitten.com/40/40"></div>

<div id="image_container" >
<p id="text_header" > Back to Green</p>
<img src="http://placekitten.com/300/400" />
<img src="http://placekitten.com/300/398" />
</div>
<div class="arrow down_arrow"><img src="http://placekitten.com/40/40"></div>

关于JQuery Scroll Top my image when onmousever,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37305776/

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