簡單的實(shí)現(xiàn)點(diǎn)擊箭頭圖片切換的js代碼
更新時(shí)間:2012年11月15日 10:36:38 作者:
這個(gè)是一個(gè)簡單的點(diǎn)擊箭頭圖片切換的例子。JS部分采用過的是jQuery
步驟如下:
(1) 準(zhǔn)備圖片(左右箭頭,以及一些示例圖片)
(2) JS(jquery)的代碼如下:
<script type="text/javascript" src="JS/jquery-1.4.4.js"></script>
<script type="text/javascript">
var picPath = new Array();
picPath.push("Images/chuang_yhb.jpg");
picPath.push("Images/dong_wgx.jpg");
picPath.push("Images/gao_xsg.jpg");
var index = 0;
$(function() {
var top = $("#img1").offset().top;
var left = $("#img1").offset().left;
var height = $("#img1").height();
var width = $("#img1").width();
$("#img1").attr({ "src": picPath[index] });
$("#img1").parent().hover(function() {
//show the arrow left and right
$("#leftArrow").show();
$("#rightArrow").show();
$("#leftArrow").css({ "left": left - 10, "top": top + (height / 2) });
$("#rightArrow").css({ "left": left + width, "top": top + (height / 2) });
}, function() {
//hide the arrrow left and right
$("#leftArrow").hide();
$("#rightArrow").hide();
});
$("#leftArrow").click(function() {
if (index > 0) {
$("#img1").attr({ "src": picPath[--index] });
}
});
$("#rightArrow").click(function() {
if (index < picPath.length) {
$("#img1").attr({ "src": picPath[++index] });
}
});
});
</script>
(3) Html部分如下:
<div>
<img id="img1" alt="Show Pictures" style="margin-left:100px;" />
<img id="leftArrow" alt="Left Arrow" src="Images/arrowa.jpg" style="position:absolute;display:none;width:50px;height:35px;z-index:99" />
<img id="rightArrow" alt="Right Arrow" src="Images/arrowb.jpg" style="position:absolute;display:none;width:50px;height:35px;z-index:99" />
</div>
下面再附一個(gè)js版的
[Ctrl+A 全選 注:引入外部Js需再刷新一下頁面才能執(zhí)行]
(1) 準(zhǔn)備圖片(左右箭頭,以及一些示例圖片)
(2) JS(jquery)的代碼如下:
復(fù)制代碼 代碼如下:
<script type="text/javascript" src="JS/jquery-1.4.4.js"></script>
<script type="text/javascript">
var picPath = new Array();
picPath.push("Images/chuang_yhb.jpg");
picPath.push("Images/dong_wgx.jpg");
picPath.push("Images/gao_xsg.jpg");
var index = 0;
$(function() {
var top = $("#img1").offset().top;
var left = $("#img1").offset().left;
var height = $("#img1").height();
var width = $("#img1").width();
$("#img1").attr({ "src": picPath[index] });
$("#img1").parent().hover(function() {
//show the arrow left and right
$("#leftArrow").show();
$("#rightArrow").show();
$("#leftArrow").css({ "left": left - 10, "top": top + (height / 2) });
$("#rightArrow").css({ "left": left + width, "top": top + (height / 2) });
}, function() {
//hide the arrrow left and right
$("#leftArrow").hide();
$("#rightArrow").hide();
});
$("#leftArrow").click(function() {
if (index > 0) {
$("#img1").attr({ "src": picPath[--index] });
}
});
$("#rightArrow").click(function() {
if (index < picPath.length) {
$("#img1").attr({ "src": picPath[++index] });
}
});
});
</script>
(3) Html部分如下:
復(fù)制代碼 代碼如下:
<div>
<img id="img1" alt="Show Pictures" style="margin-left:100px;" />
<img id="leftArrow" alt="Left Arrow" src="Images/arrowa.jpg" style="position:absolute;display:none;width:50px;height:35px;z-index:99" />
<img id="rightArrow" alt="Right Arrow" src="Images/arrowb.jpg" style="position:absolute;display:none;width:50px;height:35px;z-index:99" />
</div>
下面再附一個(gè)js版的
[Ctrl+A 全選 注:引入外部Js需再刷新一下頁面才能執(zhí)行]
您可能感興趣的文章:
相關(guān)文章
超級(jí)經(jīng)典一套鼠標(biāo)控制左右滾動(dòng)圖片帶自動(dòng)翻滾
鼠標(biāo)控制左右滾動(dòng)圖片帶自動(dòng)翻滾2008-06-06ie8.0下顯示本地圖片的js實(shí)現(xiàn)代碼 img.src
ie8.0下顯示本地圖片的js實(shí)現(xiàn)代碼,IE8.0 顯示本地圖片 img.src=本地圖片路徑 是無效,只能通過div來完成2012-03-03js實(shí)現(xiàn)圖片加載時(shí)候逐漸出現(xiàn)的雜色效果
有一些網(wǎng)站在加載圖片的時(shí)候不是一下子就出來了,而是由模糊到清淅,或是由一種不占用過多網(wǎng)絡(luò)資源的方式先大致顯示,然后再慢慢加載,避免因用戶等不及將網(wǎng)頁關(guān)掉,像馬賽克效果、沙子效果等2010-08-08用javascript實(shí)現(xiàn)旋轉(zhuǎn)圖片效果的代碼
用javascript實(shí)現(xiàn)旋轉(zhuǎn)圖片效果的代碼...2007-11-11