jquery左右滚动焦点图banner图片鼠标经过显示上下页按钮

jquery左右滚动焦点图banner图片,鼠标经过显示上下页,适合宽和高都比较大的页面使用附演示,感兴趣的朋友可以参考下

jquery左右滚动焦点图banner图片,鼠标经过显示上下页
适合宽和高都比较大的页面使用。
<div class="bannerbox"> 
<div id="focus">
<ul>
<li><a href="http://www.jbxue.com/" target="_blank">
<img src="../dandong.png" alt="" /></a></li>
<li><a href="http://www.jbxue.com/" target="_blank">
<img src="../mohe.png" alt="" /></a></li>
<li><a href="http://www.freejs.net/" target="_blank">
<img src="../changbaishan.png" alt="" /></a></li>
<li><a href="http://www.freejs.net/" target="_blank">
<img src="../erlianhaote.png" alt="" /></a></li>
</ul>
</div>
</div>


css代码:
@charset "utf-8"; 
img { border: 0px; }
.bannerbox { width: 320px; height: 150px; overflow: hidden; margin: 0px auto; }
#focus { width: 320px; height: 150px; clear: both; overflow: hidden; position: relative; float: left; }
#focus ul { width: 320px; height: 150px; float: left; position: absolute; clear: both; padding: 0px; margin: 0px; }
#focus ul li { float: left; width: 320px; height: 150px; overflow: hidden; position: relative; padding: 0px; margin: 0px; }
#focus .preNext { width: 250px; height: 150px; position: absolute; top: 0px; cursor: pointer; }
#focus .pre { left: 0; background: url(../images/sprite.png) no-repeat left center; }
#focus .next { rightright: 0; background: url(../images/sprite1.png) no-repeat rightright center; }


js文件
$(function () { 
var sWidth = $("#focus").width();
var len = $("#focus ul li").length;
var index = 0;
var picTimer;
var btn = "<div class='btnBg'></div><div class='btn'>";
for (var i = 0; i < len; i++) {
btn += "<span></span>";
}
btn += "</div><div class='preNext pre'></div><div class='preNext next'></div>";
$("#focus").append(btn);
$("#focus .btnBg").css("opacity", 0);
$("#focus .btn span").css("opacity", 0.4).mouseenter(function () {
index = $("#focus .btn span").index(this);
showPics(index);
}).eq(0).trigger("mouseenter");
$("#focus .preNext").css("opacity", 0.0).hover(function () {
$(this).stop(true, false).animate({ "opacity": "0.5" }, 300);
}, function () {
$(this).stop(true, false).animate({ "opacity": "0" }, 300);
});
$("#focus .pre").click(function () {
index -= 1;
if (index == -1) { index = len - 1; }
showPics(index);
});
$("#focus .next").click(function () {
index += 1;
if (index == len) { index = 0; }
showPics(index);
});
$("#focus ul").css("width", sWidth * (len));
$("#focus").hover(function () {
clearInterval(picTimer);
}, function () {
picTimer = setInterval(function () {
showPics(index);
index++;
if (index == len) { index = 0; }
}, 2800);
}).trigger("mouseleave");
function showPics(index) {
var nowLeft = -index * sWidth;
$("#focus ul").stop(true, false).animate({ "left": nowLeft }, 300);
$("#focus .btn span").stop(true, false).animate({ "opacity": "0.4" }, 300).eq(index).stop(true, false).animate({ "opacity": "1" }, 300);
}
});
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用jquery的animate()函数实现图片横向滚动的效果,具体实现步骤如下: 1. HTML结构:使用ul和li标签实现图片列表,并添加左右按钮。 ``` <div class="scroll-container"> <ul class="scroll-list"> <li><img src="image1.jpg"></li> <li><img src="image2.jpg"></li> <li><img src="image3.jpg"></li> <li><img src="image4.jpg"></li> </ul> <div class="scroll-btn scroll-btn-left"></div> <div class="scroll-btn scroll-btn-right"></div> </div> ``` 2. CSS样式:设置容器的宽度和高度,并使图片横向排列。 ``` .scroll-container { position: relative; width: 600px; height: 300px; overflow: hidden; } .scroll-list { position: absolute; top: 0; left: 0; width: 9999px; height: 300px; overflow: hidden; white-space: nowrap; } .scroll-list li { display: inline-block; width: 600px; height: 300px; } ``` 3. JS代码:给左右按钮添加点击事件,通过animate()函数实现图片的横向滚动。 ``` $(function(){ var $scrollList = $('.scroll-list'); var $scrollItem = $('.scroll-list li'); var itemWidth = $scrollItem.outerWidth(true); var scrollWidth = itemWidth * $scrollItem.length; var leftPos = $scrollList.position().left; var minPos = - (scrollWidth - $scrollList.parent().width()); $('.scroll-btn-left').click(function(){ if (leftPos < 0) { leftPos += itemWidth; $scrollList.animate({left: leftPos + 'px'}, 500); } }); $('.scroll-btn-right').click(function(){ if (leftPos > minPos) { leftPos -= itemWidth; $scrollList.animate({left: leftPos + 'px'}, 500); } }); }); ``` 以上代码实现了点击左右按钮图片横向滚动的效果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值