gpt4 book ai didi

javascript - 如何通过jquery从上到下更改图像

转载 作者:行者123 更新时间:2023-11-30 12:37:38 25 4
gpt4 key购买 nike

我在 jsfiddle 中有广告代码: Fiddle

如何将 2 个广告更改为在我滚动页面时始终显示底部(或更改填充/边距底部)

HTML

<div class="wrapper">
<div class="adsl">
<image alt='scoll1-2tieng' src='http://www.maydoduonghuyet.com.vn/uploads/partners/scoll1_2tieng.gif' width='120' height='300' />
</div>
<div class="adsr">
<image alt='scoll2-hdsd' src='http://www.maydoduonghuyet.com.vn/uploads/partners/scoll2_hdsd.jpg' width='120' height='300' />
</div>
</div>

jQuery:

$(document).ready(function() {

var sidebar = $(".adsl");
var offset = sidebar.offset();
var topPadding = 15;
$(window).scroll(function() {
if ($(window).scrollTop() > offset.top) {
sidebar.stop().animate({
marginTop: $(window).scrollTop() - offset.top + topPadding
});
} else {
sidebar.stop().animate({
marginTop: 0
});
}
});
var sidebar2 = $(".adsr");
var offset2 = sidebar2.offset();
var topPadding2 = 15;
$(window).scroll(function() {
if ($(window).scrollTop() > offset.top) {
sidebar2.stop().animate({
marginTop: $(window).scrollTop() - offset.top + topPadding2
});
} else {
sidebar2.stop().animate({
marginTop: 0
});
}
});
});

==更新==

感谢所有的支持和想法。我按想法位置
完成了问题这是简单的代码:Update

    <div class="wrapper morediv">
<div class="adsl"><image alt='scoll1-2tieng' src='http://www.maydoduonghuyet.com.vn/uploads/partners/scoll1_2tieng.gif' width='120' height='300' /></div>
<div class="adsr"><image alt='scoll2-hdsd' src='http://www.maydoduonghuyet.com.vn/uploads/partners/scoll2_hdsd.jpg' width='120' height='300' /></div>
</div>

仅CSS:

.wrapper{
margin:0 auto;
width: 500px;
height: 1600px;
position:relative;
background: #FF0004
}

.adsl{
position: fixed; margin-left: -135px; bottom: 0
}
.adsr{
position: fixed; margin-left: 515px; bottom: 0
}

谢谢大家

最佳答案

如果您必须始终在底部展示广告,请使用position:fixed;

demo

.adsl img, .adsr img {
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
position:fixed;
bottom:0px;
}

.adsl img{
left:0; /* set image to left */
z-index:90;
}

.adsr img{
right:0; /* set image to right */
z-index:90;
}

关于javascript - 如何通过jquery从上到下更改图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25565541/

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