jquery左右滾動焦點圖banner圖片鼠標經(jīng)過顯示上下頁按鈕
更新時間:2013年10月11日 15:18:50 作者:
jquery左右滾動焦點圖banner圖片,鼠標經(jīng)過顯示上下頁,適合寬和高都比較大的頁面使用附演示,感興趣的朋友可以參考下
jquery左右滾動焦點圖banner圖片,鼠標經(jīng)過顯示上下頁
適合寬和高都比較大的頁面使用
演示
<div class="bannerbox">
<div id="focus">
<ul>
<li><a target="_blank">
<img src="../dandong.png" alt="" /></a></li>
<li><a target="_blank">
<img src="../mohe.png" alt="" /></a></li>
<li><a target="_blank">
<img src="../changbaishan.png" alt="" /></a></li>
<li><a target="_blank">
<img src="../erlianhaote.png" alt="" /></a></li>
</ul>
</div>
</div>
@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);
}
});
適合寬和高都比較大的頁面使用
演示
復制代碼 代碼如下:
<div class="bannerbox">
<div id="focus">
<ul>
<li><a target="_blank">
<img src="../dandong.png" alt="" /></a></li>
<li><a target="_blank">
<img src="../mohe.png" alt="" /></a></li>
<li><a target="_blank">
<img src="../changbaishan.png" alt="" /></a></li>
<li><a target="_blank">
<img src="../erlianhaote.png" alt="" /></a></li>
</ul>
</div>
</div>
復制代碼 代碼如下:
@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);
}
});
您可能感興趣的文章:
- 基于JQuery的實現(xiàn)圖片輪播效果(焦點圖)
- jquery仿QQ商城帶左右按鈕控制焦點圖片切換滾動效果
- jquery焦點圖片切換(數(shù)字標注/手動/自動播放/橫向滾動)
- jQuery焦點圖切換特效插件封裝實例
- jQuery焦點圖切換簡易插件制作過程全紀錄
- Jquery焦點圖實例代碼
- Jquery 焦點圖 用于圖片展示效果代碼
- jQuery插件實現(xiàn)帶圓點的焦點圖片輪播切換
- jQuery插件Elastislide實現(xiàn)響應式的焦點圖無縫滾動切換特效
- jquery picswitch圖片焦點圖展示效果
- jQuery插件bxSlider實現(xiàn)響應式焦點圖
- jQuery實現(xiàn)的自適應焦點圖效果完整實例
相關文章
jquery中的mouseleave和mouseout的區(qū)別 模仿下拉框效果
不論鼠標指針離開被選元素還是任何子元素,都會觸發(fā) mouseout 事件,只有在鼠標指針離開被選元素時,才會觸發(fā) mouseleave 事件2012-02-02
jquery實現(xiàn)兩個div中的元素相互拖動的方法分析
這篇文章主要介紹了jquery實現(xiàn)兩個div中的元素相互拖動的方法,結合實例形式分析了jQuery基于鼠標事件響應的頁面元素屬性動態(tài)操作相關實現(xiàn)技巧,需要的朋友可以參考下2020-04-04
ztree實現(xiàn)左邊動態(tài)生成樹右邊為內(nèi)容詳情功能
zTree 是利用 JQuery 的核心代碼,實現(xiàn)一套能完成大部分常用功能的 Tree 插件。接下來通過本文給大家分享ztree實現(xiàn)左邊動態(tài)生成樹右邊為內(nèi)容詳情功能,需要的朋友參考下吧2017-11-11

